POV-Ray : Newsgroups : povray.advanced-users : Average of vectors? : Re: Average of vectors? Server Time
26 Sep 2024 17:45:47 EDT (-0400)
  Re: Average of vectors?  
From: Warp
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

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