help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotation matrix definition


From: Farzad Torabi
Subject: Re: Rotation matrix definition
Date: Mon, 25 Nov 2019 14:06:03 +0100





On Fri, Nov 22, 2019 at 12:35 PM <address@hidden> wrote:


> Il giorno 21 nov 2019, alle ore 14:55, Farzad Torabi <address@hidden> ha scritto:
>
> loading the nurbs package , it seemed to be working.
>
> ok, let's make the example, the vector X of the new CS is :  [-115.830   -16.850   113.400] in the global CS
>
> I myself used the
>
> anglex = atan2(norm(cross(a,b)), dot(a,b))
>
> to check the angle between Xglobal and Xnew and it should be 44.7° ( also checked with CAD)
>
> so my next steps could have been finding the angles with all other axes and then form the transformation matrix and multiply it in the old Vecotr
>
> but
> instead,  using the proposed formula :
>
> T = vecrot(pi, (vecXnew + [1; 0; 0])/2)
>
> I get
>
> T =
>
>   -0.66887   0.33401   0.33401   0.00000
>    0.33401  -0.66308   0.33692   0.00000
>    0.33401   0.33692  -0.66308   0.00000
>    0.00000   0.00000   0.00000   1.00000
>
> is it the same result ? meaning : the total transformation matrix ?


mmmh... I was assuming your vector would be a COLUMN but instead you have a ROW.
This creates an issue which is connected to broadcasting (see [1] to understand what broadcasting is
and how it works).

In short (vecnorm (vecXnew) + [1; 0; 0])/2 is supposed to give the average between vecXnew
normalized and the x-axis but, if vecXnew is a row you get a matrix instead of a vector:

> (vecXnew + [1; 0; 0])/2
ans =

  -57.4150   -7.9250   57.2000
  -57.9150   -8.4250   56.7000
  -57.9150   -8.4250   56.7000


to get the correct answer you have to make sure your vector is a COLUMN

> (vecXnew(:) + [1; 0; 0])/2
ans =

  -57.4150
   -8.4250
   56.7000

so the correct syntax is in your case :

 T = vecrot(pi, (vecnorm (vecXnew(:)) + [1; 0; 0])/2)

and you can check that it does the expected transformation
by verifying that

 > norm (T * [1;0;0;1] - [vecnorm(vecXnew(:)); 1] , inf)
ans = 1.2490e-16

so, if you apply T to the x-axis direction you do get
your vector direction.

Notice that I am using 4x1 vectors and 4x4 matrices
as this works with homogeneous coordinates [2]

The standard 3x3 rotation matrix is the upper left block of T:

> norm (T(1:3,1:3) * vecnorm(vecXnew(:)) - [1; 0; 0], inf)
ans = 1.1102e-16

c.



[1] https://octave.org/doc/interpreter/Broadcasting.html#Broadcasting
[2] https://en.wikipedia.org/wiki/Homogeneous_coordinates


I add one more question :  I think the rotation matrix is only to find the new coordinates of the points in a "Rotated" coordinate system. But I am talking about converting translations and rotations :

so in this case, if  I have to transform the movement x= 4.6 , y=6.5, z= 7.8 , Rx= 1 ° , Ry= 2.6, Rz= 0.5 , how do I use T ? multiplying in the XYZRxRyRz matrix ?
 




 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]