POV-Ray : Newsgroups : povray.advanced-users : Convert matrix to rotate ? : Re: Convert matrix to rotate ? Server Time
30 Jul 2024 02:18:14 EDT (-0400)
  Re: Convert matrix to rotate ?  
From: Rune
Date: 20 May 2000 10:01:38
Message: <39269ac2@news.povray.org>
"Ken" wrote:
> Rune wrote:
> > So is there any way?
>
> If it is possible these two sites will tell you -
>
> http://www.gate.net/~shipbrk/raytrace/matrix.html
> http://www.erols.com/vansickl/matrix.htm

No of those pages explain how to do what I want to do, although the second
one comes close. But thanks for the links anyway! :-)

I found the solution of my problem myself.
The first macro is just a macro needed by the second macro.
The second macro do what I wanted to do.

// 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) // by Rune S. Johansen
   #local Angle = degrees(acos(vdot(vnormalize(V1),vnormalize(V2))));
   #if (
      (vlength(About)!=0)
      &

(vlength(vaxis_rotate(V1,-About,Angle)-V2)<vlength(vaxis_rotate(V1,About,Ang
le)-V2))
   )
      #local Angle = -Angle;
   #end
   Angle
#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(X,-RotZ*z),y);
   #local RotX = FindAngle(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
   <RotX,RotY,RotZ>
#end

Greetings,

Rune

---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!


Post a reply to this message

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