POV-Ray : Newsgroups : povray.advanced-users : Average of vectors? Server Time
1 Nov 2024 23:14:23 EDT (-0400)
  Average of vectors? (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Rune
Subject: Average of vectors?
Date: 7 Jan 2001 15:46:31
Message: <3a58d5a7@news.povray.org>
Imagine two vectors, A and B.
C is a regular weighted average of the two vectors, say clock*A +
(1-clock)*B.

With this type of average the vector-point is linearly "interpolated", but
the rotation and length of the vector is not.

To make the length of C linearly interpolated is easy, but how do I linearly
interpolate the "rotation"?

I need a general method that can average not just two, but multiple vectors.
How can I do this?

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 6)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Warp
Subject: Re: Average of vectors?
Date: 7 Jan 2001 16:26:32
Message: <3a58df08@news.povray.org>
A start:

camera { location <0,2,-6>*.8 look_at 0 angle 35 translate y*.5}
light_source { y*100, 1 }
plane { y,0 pigment { checker rgb 1, rgb .5 } }

#declare A = <-1,1.5,0>;
#declare B = <1,.5,.5>;

cylinder { 0,A,.025 pigment { rgb x } }
cylinder { 0,B,.025 pigment { rgb x } }

#declare An = vnormalize(A);
#declare Bn = vnormalize(B);
#declare Al = vlength(A);
#declare Bl = vlength(B);
#declare Angle = degrees(acos(vdot(An,Bn)));
#declare Perp = vcross(A,B);

#declare Clock=0;
#while(Clock<=1)
  #declare Len = Al*(1-Clock)+Bl*Clock;
  #declare C = vaxis_rotate(An, Perp, Angle*Clock)*Len;
  cylinder { 0,C,.02 pigment { rgb x+y } }
  #declare Clock=Clock+.1;
#end


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


Post a reply to this message

From: Warp
Subject: Re: Average of vectors?
Date: 7 Jan 2001 16:29:30
Message: <3a58dfb9@news.povray.org>
PS: If you need an explanation about the math used, just ask.

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


Post a reply to this message

From: Rune
Subject: Re: Average of vectors?
Date: 7 Jan 2001 17:27:07
Message: <3a58ed3b@news.povray.org>
"Warp" wrote:
> PS: If you need an explanation about the math used, just ask.

Thanks, I understand it well with two vectors, but I don't quite grasp how
to handle n vectors... It hasn't really anything to do with the clock like
in the example; it was just easier for me to explain what I meant that way.
What I need is a weighted average on n vectors V[N], each with their own
weight W[N].

How can that be done?

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 6)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Rune
Subject: Re: Average of vectors?
Date: 7 Jan 2001 17:42:41
Message: <3a58f0e1$1@news.povray.org>
"Rune" wrote:
> What I need is a weighted average on n vectors V[N], each
> with their own weight W[N].

Well, let me just reveal that what I ultimately want to do is to take an
average of multiple matrixes. Got any ideas?

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 6)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Warp
Subject: Re: Average of vectors?
Date: 7 Jan 2001 18:12:53
Message: <3a58f7f5@news.povray.org>
Rune <run### [at] inamecom> wrote:
: Thanks, I understand it well with two vectors, but I don't quite grasp how
: to handle n vectors... It hasn't really anything to do with the clock like
: in the example; it was just easier for me to explain what I meant that way.
: What I need is a weighted average on n vectors V[N], each with their own
: weight W[N].

  Perhaps something like this:

#declare C = <0,0,0>;
#declare Clen = 0;
#declare TotalW = 0;
#declare Ind = 0;
#while(Ind<Amount)
  #declare C = C+vnormalize(V[Ind])*W[Ind];
  #declare Clen = Clen+vlength(V[Ind])*W[Ind];
  #declare TotalW = TotalW+W[Ind];
  #declare Ind=Ind+1;
#end
#declare C = vnormalize(C/TotalW)*(Clen/TotalW);

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


Post a reply to this message

From: David Fontaine
Subject: Re: Average of vectors?
Date: 7 Jan 2001 19:09:50
Message: <3A590430.7C55FB4B@faricy.net>
Rune wrote:

> Imagine two vectors, A and B.
> C is a regular weighted average of the two vectors, say clock*A +
> (1-clock)*B.
>
> With this type of average the vector-point is linearly "interpolated", but
> the rotation and length of the vector is not.
>
> To make the length of C linearly interpolated is easy, but how do I linearly
> interpolate the "rotation"?
>
> I need a general method that can average not just two, but multiple vectors.
> How can I do this?

Make normalized copies of the two vectors, a and b.
Find the angle, A, between them: 2*asin(vlength(b-a)/2).
The vector you want is (a+b)/2 + tan(-A/2+A*clock)*vlength((a+b)/2)*vnorm(b-a)
Where clock goes from 0 to 1 from vector a to vector b.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: David Fontaine
Subject: Re: Average of vectors?
Date: 7 Jan 2001 19:10:25
Message: <3A590456.80845E16@faricy.net>
David Fontaine wrote:

> Make normalized copies of the two vectors, a and b.
> Find the angle, A, between them: 2*asin(vlength(b-a)/2).
> The vector you want is (a+b)/2 + tan(-A/2+A*clock)*vlength((a+b)/2)*vnorm(b-a)
> Where clock goes from 0 to 1 from vector a to vector b.

This math is untested BTW.

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

From: Warp
Subject: Re: Average of vectors?
Date: 8 Jan 2001 05:55:34
Message: <3a599ca5@news.povray.org>
Btw, the code I posted probably doesn't make what you want. Sorry.

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


Post a reply to this message

From: Josh English
Subject: Re: Average of vectors?
Date: 8 Jan 2001 08:00:11
Message: <3A59BA2F.D5B3D8CC@spiritone.com>
I just tackled this problem myself:

given vectors v0, v1 (I assume they are at the origin)
#declare vn = vnormalize(vcross(v0,v1));
#declare v2 =
vaxis_rotate(v0,vn,clock*degrees(acos(vdot(vo,v1)/(vlength(v0)*vlength(v1)))));

v2 is in the right direction, so normalize it and adjust the length normally.

Josh

Rune wrote:

> Imagine two vectors, A and B.
> C is a regular weighted average of the two vectors, say clock*A +
> (1-clock)*B.
>
> With this type of average the vector-point is linearly "interpolated", but
> the rotation and length of the vector is not.
>
> To make the length of C linearly interpolated is easy, but how do I linearly
> interpolate the "rotation"?
>
> I need a general method that can average not just two, but multiple vectors.
> How can I do this?
>
> Rune
> --
> \ Include files, tutorials, 3D images, raytracing jokes,
> / The POV Desktop Theme, and The POV-Ray Logo Contest can
> \ all be found at http://rsj.mobilixnet.dk (updated January 6)
> / Also visit http://www.povrayusers.org

--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritonecom
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

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