POV-Ray : Newsgroups : povray.advanced-users : Average of vectors? Server Time
30 Jul 2024 00:28:58 EDT (-0400)
  Average of vectors? (Message 3 to 12 of 12)  
<<< Previous 2 Messages Goto Initial 10 Messages
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

From: Rune
Subject: Re: Average of vectors?
Date: 8 Jan 2001 13:27:03
Message: <3a5a0677@news.povray.org>
"Warp" wrote:
> Btw, the code I posted probably doesn't make what you want. Sorry.

Thanks anyway!

Maybe it'll be good enough if the vector lengths are linearly interpolated,
but not the rotations, and linearly interpolating the lengths isn't a
problem.

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: Tor Olav Kristensen
Subject: Re: Average of vectors?
Date: 8 Jan 2001 19:48:34
Message: <3A5A5F38.B896CE18@online.no>
Rune wrote:
>... 
> Well, let me just reveal that what I ultimately want to do is to take an
> average of multiple matrixes. Got any ideas?

"The Matrix and Quaternions FAQ" has an answer to this question:

"How do I use quaternions to perform linear interpolation 
between matrices?"

http://www.cs.ualberta.ca/~andreas/math/matrfaq_latest.html#Q61


Regards,

Tor Olav
-- 
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

<<< Previous 2 Messages Goto Initial 10 Messages

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