POV-Ray : Newsgroups : povray.general : Where's that rotation advice? : Re: Where's that rotation advice? Server Time
8 Aug 2024 08:15:54 EDT (-0400)
  Re: Where's that rotation advice?  
From: Greg M  Johnson
Date: 22 Jan 2001 09:52:25
Message: <3A6C47CE.59086ECB@my-dejanews.com>
Thanks all.  Rune actually answered this question in July. Because it was
so useful, I'm pasting it here again:

// By Rune Johansen, Thu, 6 Jul 2000
// Perpendiculize will adjust the vector V1
// so that it is perpendicular to the vector V2.
// The input is V1 and V2, and the macro returns
// the adjusted version of V1.
#macro Perpendiculize (V1,V2) // by Rune S. Johansen
   vnormalize(vcross(vcross(V2,V1),V2))
#end

// FindAngle will find the angle between V1 and V2.
// The third parameter "About" is a vector which must be
// perpendicular to both V1 and V2. If the rotation from
// V1 to V2 about "About" is negative, the returned angle
// is negative. ( When you look in the direction of "About"
// clockwise is negative and anticlockwise is positive. )
// If you set "about" to <0,0,0> the returned angle will
// always be positive (or zero).
#macro FindAngle (V1,V2,About)
   degrees(acos(vdot(vnormalize(V1),vnormalize(V2))))
   *(vdot(About,vcross(V1,V2))<0?-1:1)
#end

// Given 2 vectors, a vector for the X direction
// (similar to the 1st - 3rd number in a matrix),
// and one for the Y direction (similar to the
// 4th - 6th number in a matrix), Vectors2Rotate will
// return a rotation vector which will transform an
// object in the same way as a matrix using the
// vectors would do. VectorX and VectorY must be
// perpendicular to each other.
#macro Vectors2Rotate (VectorX,VectorY) // by Rune S. Johansen
   #local RotZ = FindAngle(x,<VectorX.x,VectorX.y,0>,z);
   #local RotY = FindAngle(x,vrotate(VectorX,-RotZ*z),y);
   #local RotX = FindAngle(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
   <RotX,RotY,RotZ>
#end


Post a reply to this message

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