POV-Ray : Newsgroups : povray.advanced-users : finding the rotation vector of the transformation between two reference fra= : Re: finding the rotation vector of the transformation between two reference= Server Time
4 Oct 2024 17:01:56 EDT (-0400)
  Re: finding the rotation vector of the transformation between two reference=  
From: Grassblade
Date: 13 Apr 2007 12:10:01
Message: <web.461faa809a56f91516325b850@news.povray.org>
"chrissounette" <nomail@nomail> wrote:
> Thanks, but it is not so simple. In fact, let consider two orthogonal triads
> of unit vectors I = [Forward_1, Right_1, Up_1] and J = [Forward_2, Right_2,
> Up_2] with same origin O. Determining the ZYX angles, also known as
> Roll-Pitch-Yaw angles, to denote the rotational relationship between the
> vectors of these two triads requires to compute first the rotation matrix R
> as follow:
>
> [Forward_2 | Right_2 | Up_2] = R * [Forward_1 | Right_1 | Up_1].
> -> R = [Forward_2 | Right_2 | Up_2] * [Forward_1 | Right_1 | Up_1]^(-1).
>
> Then the inverse solution to a given rotation matrix R [r11,r12,r13;
> r21,r22,r23; r31,r32,r33] can be obtained by:
>
> Roll  = Atan2(r21,r11)
> Pitch = Atan2(-r31,sqrt(r32^2+r33^2));
> Yaw   = Atan2 (r32,r33);
>
> I'm not expert in Povray yet, and I was wondering if there is a macro
> available to do implement this solution ??? If not, I would appreciate if
> somobody could help me writing such macro :-)
>
> Thanks,
> Chris

Well, I'm not an expert either (yet?), but I think I saw a macro made by
Rune that might do something like what you are looking for. I can't find
the link anymore, though.
POV-ray has commands for dealing with matrices but they are not referenced
in the manual, at least not that I could find.

A straightforward macro using my matrices.inc could go like this, assuming I
and J are the matrices made collating the three vectors:

#macro(I,J)
  #local invI=array[3][3];
  #local R=array[3][3];
  MPGinverse(I,invI) // invI = inverse of I
  matprod(J, invI, R) // R=J*invI
  #declare Roll  = atan2(R[1][0],R[0][0]);
  #declare Pitch = atan2(-R[2][0],sqrt(pow(R[2][1],2)+pow(R[2][2],2)));
  #declare Yaw   = atan2 (R[2][1],R[2][2]);
#end

I'm not sure if atan2 in POV behaves the way you want, I just left it the
way you put it in.


Post a reply to this message

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