POV-Ray : Newsgroups : povray.advanced-users : Vector average question : Re: Vector average question Server Time
29 Jul 2024 16:22:54 EDT (-0400)
  Re: Vector average question  
From: Elias Pschernig
Date: 3 Nov 2001 19:42:52
Message: <3be48f0c@news.povray.org>
> If I have a bunch of random 3-d vectors, is there a way I can find a new
> vector that is as close as possible to being perpendicular to as many as
> possible of the vectors?
> 
> ...or practically the same question formulated differently: If I have a
> bunch of random points, how can I find the normal of the plane that is as
> close as possible to as many as possible of the points? (The average
> distance from a point to the plane should be as small as possible.)

I would do the latter like this:

Take any 3 points, and build the cross product. Do this for all possibilities
of 3 points. So e.g. if you have 3 points, you get one cross product. If you
have 4 points, you get 6 cross products, and so on..

e.g. for A, B, C, D you do vcross(A-B, B-C), vcross(B-C, C-D), ...

Then, make all the vectors you got this way point to the same side. I forgot
how you do that, but probably you can just take a reference point a bit away
from the others, and then check if they are flipped.

Then "average" all these vectors together (i.e. add them), and take the result
as the normal to your plane.

I was just thinking this up right now, so it might be completely wrong, and
it sure is quite inefficient. But maybe it gives you some thought about a
solution :) If you want me to write it down mathematically or as POV code,
i could probably do that tomorrow. (Right now I'm too tired)

-- 
#macro C(X,Y)cylinder{X*x<X,0,-Y/2>.1}#end#macro U(R,X,Y)intersection{torus{.9
.1}box{-1 0rotate y*R*90}translate<X,0,Y>scale 1-z*.5}#end union{U(0,0,0)U(1,0
,0)U(2,-1,-1)U(1,1,0)U(1,1.5,-3)U(1,2,0)U(3,1,0)U(2,2,0)U(0,3,0)U(3,2,.5)C(.1,
2)C(.8,1)C(.8,-1)C(1.1,1)C(1.9,-1)pigment{rgb 10}rotate x*90translate<-1,0,4>}


Post a reply to this message

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