POV-Ray : Newsgroups : povray.general : Perpendicular to an arbitrary axis : Re: Perpendicular to an arbitrary axis Server Time
2 Aug 2024 20:19:16 EDT (-0400)
  Re: Perpendicular to an arbitrary axis  
From: Slime
Date: 2 Aug 2004 19:30:17
Message: <410ece89$1@news.povray.org>
>    #local x_point = vcross(l_source, l_point_at); // get a perpendicular

Well, if l_source and l_point_at are parallel vectors, then vcross will give
you <0,0,0> as its result.

It looks to me like you're trying to get a vector perpendicular to
l_point_at, but it doesn't matter what vector it is as long as it's
perpendicular.

To get a vector perpendicular to another vector, you just do a vcross with
any other vector:

#local x_point = vcross(x, l_point_at); // get a perpendicular

But this can always pose a problem, since you have to ensure that the vector
you choose (x in this case, l_source in your case) isn't parallel to the
vector you're finding a perpendicular for (l_point_at).

The simplest solution is this:

#local x_point = vcross(x, l_point_at);
#if (vlength(x_point) = 0)
    #local x_point = vcross(y, l_point_at); // if x was parallel to
l_point_at, try y instead
#end

In any case, there is a function in math.inc, VPerp_To_Vector(V), which will
find a vector perpendicular to l_point_at if you do
VPerp_To_Vector(l_point_at). I wouldn't be surprised if it uses the same
method I just mentioned.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

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