POV-Ray : Newsgroups : povray.advanced-users : vlength( ) Server Time
26 Nov 2024 11:32:20 EST (-0500)
  vlength( ) (Message 1 to 10 of 18)  
Goto Latest 10 Messages Next 8 Messages >>>
From: SamuelT
Subject: vlength( )
Date: 9 Jun 2000 00:20:00
Message: <3940710D.6EAE55D@aol.com>
Does anybody know how vlength converts vectors to floats? I've use it,
but I'm interested in knowing what the output is. Does it average the
vector numbers to create one float? Thanks in advance.

--
Samuel Benge

E-Mail: STB### [at] aolcom

Visit my isosurface tutorial at http://members.aol.com/stbenge


Post a reply to this message

From: Chris Colefax
Subject: Re: vlength( )
Date: 9 Jun 2000 00:38:09
Message: <394074b1@news.povray.org>
SamuelT <STB### [at] aolcom> wrote:
> Does anybody know how vlength converts vectors to floats? I've use it,
> but I'm interested in knowing what the output is. Does it average the
> vector numbers to create one float? Thanks in advance.

I think you'll find it uses something more Pythagorean than a simple
average: the formula for the length of a vector (as shown in the POV-Ray
docs) is the square root of the sum of the squares of each of the vector's
components, ie:

   sqrt (vdot(V, V))

which equals:

   sqrt (V.x*V.x + V.y*V.y + V.z*V.z)

in the case, obviously, of a three dimensional vector.


Post a reply to this message

From: Jetlag
Subject: Re: vlength( )
Date: 9 Jun 2000 00:46:16
Message: <39407698@news.povray.org>
> Does anybody know how vlength converts vectors to floats? I've use it,
> but I'm interested in knowing what the output is. Does it average the
> vector numbers to create one float? Thanks in advance.

A vector is really a direction and a length (scalar), vlength just returns
the length.

In POV however, a vector is represented as a point in space by XYZ
coordinates, the direction and length aren't very obvious (to most). The
direction is considered the direction from the origin (0,0,0) to the vector
point, and the length of the vector is the length from the origin to vector
point. I think vlength(x,y,z) is just sqrt(x*x+y*y+z*z).

If I'm wrong someone please correct me.


Post a reply to this message

From: Jetlag
Subject: Re: vlength( )
Date: 9 Jun 2000 00:47:59
Message: <394076ff@news.povray.org>
wow are you 15 minutes in the future?


Post a reply to this message

From: SamuelT
Subject: Re: vlength( )
Date: 9 Jun 2000 01:05:37
Message: <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.

Chris Colefax wrote:

> SamuelT <STB### [at] aolcom> wrote:
> > Does anybody know how vlength converts vectors to floats? I've use it,
> > but I'm interested in knowing what the output is. Does it average the
> > vector numbers to create one float? Thanks in advance.
>
> I think you'll find it uses something more Pythagorean than a simple
> average: the formula for the length of a vector (as shown in the POV-Ray
> docs) is the square root of the sum of the squares of each of the vector's
> components, ie:
>
>    sqrt (vdot(V, V))
>
> which equals:
>
>    sqrt (V.x*V.x + V.y*V.y + V.z*V.z)
>
> in the case, obviously, of a three dimensional vector.

--
Samuel Benge

E-Mail: STB### [at] aolcom

Visit my isosurface tutorial at http://members.aol.com/stbenge


Post a reply to this message

From: Pabs
Subject: Re: vlength( )
Date: 9 Jun 2000 01:26:51
Message: <39408048.98CDDC1B@hotmail.com>
SamuelT wrote:

> So, is there a way to get a perfect average from a vector number?

try
$ vec = <1.1, 1.0, 0.9> //initialize the vector
$ av = (vec.x+vec.y+vec.z)/3.0 // get the average
#debug concat(str(av,0,5),"\n") //output the average - 0.90000 - 5 decimal places
 or use .red, .green & .blue instead of .x, .y & .z but .x, .y & .z work as well
you could also create a macro
#macro average(vec)
 ((vec.x+vec.y+vec.z)/3.0)
#end
or did you want something else

Pabs


Post a reply to this message

From: Simen Kvaal
Subject: Re: vlength( )
Date: 9 Jun 2000 03:45:43
Message: <3940a0a7$1@news.povray.org>
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

From: SamuelT
Subject: Re: vlength( )
Date: 9 Jun 2000 16:56:59
Message: <39415ABB.3AF4F3F6@aol.com>
Thanks guys. I'll try the simple macro for averaging the 3 components of
the vector. I seem to be getting accurate results from using one vector
inside of vlength. I'll run a test to see if it's really accurate or
not.

--
Samuel Benge

E-Mail: STB### [at] aolcom

Visit my isosurface tutorial at http://members.aol.com/stbenge


Post a reply to this message

From: Warp
Subject: Re: vlength( )
Date: 10 Jun 2000 15:42:40
Message: <39429a30@news.povray.org>
What are you trying to do?
  The average of the components of a vector doesn't sound like anything
rational. The length of a vector sound much more useful.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: SamuelT
Subject: Re: vlength( )
Date: 12 Jun 2000 18:37:00
Message: <394566DD.DAC31764@aol.com>
It's for the eval_pigment stuff I've been using. I needed to convert a color
vector into a float value so I could use it for elevation. The best way I
could think of doing this would be averaging the components of the color
vector. I'm now using a macro instead of vlength, and it works great.

Warp wrote:

>   What are you trying to do?
>   The average of the components of a vector doesn't sound like anything
> rational. The length of a vector sound much more useful.
>
> --
> main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
> ):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Goto Latest 10 Messages Next 8 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.