|
|
SamuelT skrev i meldingen <39407BC0.6E1D4081@aol.com>...
>So, is there a way to get a perfect average from a vector number? I'm
>experimenting with eval_pigment and it has become necessary to convert
vectors
>to floats.
>
Well, mathematically speaking, there is no such thing as "an average from a
vector number," But if you want the average of the components, just add and
divide, like this:
#macro average1(foo)
((foo.x+foo.y+foo.z)/3)
#end
If you want the average from, say n vectors, do this:
#macro average2(array_of_vectors, num) // assume first entry is at index 0.
#local sum=<0, 0, 0>;
#local c=0;
#while (c<num)
#local sum = sum + array_of_vectors[i];
#local c=c+1;
#end
(sum/num)
#end
I think it should work at first try ... This macro creates a vector whose
components are the average of the respective components of the vectors in
question.
As, the others here pointed out, vlength() returns the length of a vector.
Another way to think of a vector is a point in space with xyz-coordinates as
the components in the vector. vlength() then returns the distance from <0,
0, 0> to <x, y, z>, in other words the lengt of the straight line joining
those two points. Thus, vlength could be regarded as some kind of "average"
of the components; if one are willing to use the word a bit freely...
Regards,
Simen.
Post a reply to this message
|
|