-
Normalize Vector Issue
Hi all.
I have the following expression code on a Text Layer’s Source Text (for debugging purposes).
It’s working fine except that I’m only getting different random values for each array (pArray1) when I normalize the vector (normalise = true)
In other words, if I set the variable normalise to false then each of the pArray1 amounts come out the same.
Any idea why?
Thanks,
Jamie
seedRandom(index, true);parentType1 = [0, 0, 0];
parentAmount1 = 4;
minMax1 = [-1, 1];
normalise1 = true;pArray1 = generateParents(parentType1, parentAmount1, minMax1, normalise1);
str1 = "";
for (n1 = 0; n1 < parentAmount1; n1++) {
str1 += "Parent " + n1 + "\r";
for (n2 = 0; n2 < parentType1.length; n2++) {
str1 +=
"\t" + "[" + n2 + "]: " + pArray1[n1][n2] + "\t" + "\r";}
str1 += "\t" + "length: " + length(pArray1[n1]) + "\r" +
"\r";
}function generateParents(pType_1, pAmount_1, minMax_1, norm_1) {
var pArray_1 = new Array();
var pType_2 = new Array();
for (n_2 = 0; n_2 < pAmount_1; n_2++) {
for (n_1 = 0; n_1 < pType_1.length; n_1++) {
pType_2[n_1] = random(minMax_1[0], minMax_1[1]);
}
if (norm_1) {
pType_3 = normalize(pType_2);
} else {
pType_3 = pType_2;
}
pArray_1[n_2] = pType_3;
}
return(pArray_1);
}JimJam•Graphics
https://www.jimjamgraphics.com/