[ODE] Vector that's perpendicular to two others
Nate W
coding at natew.com
Fri Apr 5 12:51:02 2002
On Thu, 4 Apr 2002, Martin C. Martin wrote:
> dCROSS(p, =, ax1, ax2);
> dNormalize3(p);
>
> Which should work fine unless ax1 and ax2 are almost the same. For
> example, if they're both (1, 0, 0), the p will end up being (1, 0, 0) as
> well. In this case, any vector perpendicular to the two of them will
> do.
Suppose you first calculate the angle between ax1 and ax2... If it's
above some threshold (say, greater than 0.01 radians?), use the cross
product as you decribed above.
Otherwise, find a vector that's perpendicular to just ax1, perhaps by
cooking up an arbitrary vector to use in place of ax2 in the same
cross-product code. Like, change the sign on the largest element of ax1
and use that in place of ax2?
No warranty expressed or implied, I'm making this up as I go along. :-)
--
Nate Waddoups
Redmond WA USA
http://www.natew.com