Rotation matrix definition

classic Classic list List threaded Threaded
26 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Rotation matrix definition

Farzadtb
Hi All

I need to convert the translations + rotations from global coordinate system into a new coordinate system that is translated+rotated from the global one. How do I obtain that ?

--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-2


> Il giorno 21 nov 2019, alle ore 10:11, Farzad Torabi <[hidden email]> ha scritto:
>
> I need to convert the translations + rotations from global coordinate system into a new coordinate system that is translated+rotated from the global one. How do I obtain that ?
>

This sounds like homework, is it?

If so, we usually avoid providing directly solutions to students' homework,
(and it would be particularly inappropriate in this case as we are in the same University)

That said, I think it is OK to provide some pointers.

Affine transformations in R^3 can be conveniently represented as (4x4) Matrix times (4x1)
vector multiplications using homogeneus coordinates, you can find the theory about this
in any undergraduate text on linear algebra and geometry.

The package "nurbs" contains utility functions "vecrot" and "vectrans" that help you construct
the appropriate matrices representing an affine transformation.

hope this helps,
c.




Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
It's not a homework. I'm not a student 

Il gio 21 nov 2019, 10:34 Carlo De Falco <[hidden email]> ha scritto:


> Il giorno 21 nov 2019, alle ore 10:11, Farzad Torabi <[hidden email]> ha scritto:
>
> I need to convert the translations + rotations from global coordinate system into a new coordinate system that is translated+rotated from the global one. How do I obtain that ?
>

This sounds like homework, is it?

If so, we usually avoid providing directly solutions to students' homework,
(and it would be particularly inappropriate in this case as we are in the same University)

That said, I think it is OK to provide some pointers.

Affine transformations in R^3 can be conveniently represented as (4x4) Matrix times (4x1)
vector multiplications using homogeneus coordinates, you can find the theory about this
in any undergraduate text on linear algebra and geometry.

The package "nurbs" contains utility functions "vecrot" and "vectrans" that help you construct
the appropriate matrices representing an affine transformation.

hope this helps,
c.




Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
In reply to this post by Carlo de Falco-2
Adding to that, that I'm not a student,
My doubt is about the order of rotations, given that from the new Cs, I only have the direction of one of its axes. 



Il gio 21 nov 2019, 10:34 Carlo De Falco <[hidden email]> ha scritto:


> Il giorno 21 nov 2019, alle ore 10:11, Farzad Torabi <[hidden email]> ha scritto:
>
> I need to convert the translations + rotations from global coordinate system into a new coordinate system that is translated+rotated from the global one. How do I obtain that ?
>

This sounds like homework, is it?

If so, we usually avoid providing directly solutions to students' homework,
(and it would be particularly inappropriate in this case as we are in the same University)

That said, I think it is OK to provide some pointers.

Affine transformations in R^3 can be conveniently represented as (4x4) Matrix times (4x1)
vector multiplications using homogeneus coordinates, you can find the theory about this
in any undergraduate text on linear algebra and geometry.

The package "nurbs" contains utility functions "vecrot" and "vectrans" that help you construct
the appropriate matrices representing an affine transformation.

hope this helps,
c.




Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-2


> Il giorno 21 nov 2019, alle ore 10:38, Farzad Torabi <[hidden email]> ha scritto:
>
> Adding to that, that I'm not a student,
> My doubt is about the order of rotations, given that from the new Cs, I only have the direction of one of its axes.

If you specify better what you want to do, possibly with ane example of the code you tried to write, and the results you expected, it may be easier to help.
c.

P.S. This page on wikipedia [1] has a very extensive detailed explanation of rotation matrices.

[1] https://en.wikipedia.org/wiki/Rotation_matrix#Multiplication

Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
dear Carlo

I don't know the expected results, I am looking to know how to calculate them. I think my doubt is here : given that I have two points on the X axis of the new CS,  I suppose that I should calculate the angles of this vector with global axis and plus the translations ( if they happened in CS transformation). but then for the rotation matrix, given that I know the first input,  how do I define the rotation order for rotation matrix ?

On Thu, Nov 21, 2019 at 10:58 AM Carlo De Falco <[hidden email]> wrote:


> Il giorno 21 nov 2019, alle ore 10:38, Farzad Torabi <[hidden email]> ha scritto:
>
> Adding to that, that I'm not a student,
> My doubt is about the order of rotations, given that from the new Cs, I only have the direction of one of its axes.

If you specify better what you want to do, possibly with ane example of the code you tried to write, and the results you expected, it may be easier to help.
c.

P.S. This page on wikipedia [1] has a very extensive detailed explanation of rotation matrices.

[1] https://en.wikipedia.org/wiki/Rotation_matrix#Multiplication


--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-2


> Il giorno 21 nov 2019, alle ore 12:11, Farzad Torabi <[hidden email]> ha scritto:
>
> dear Carlo
>
> I don't know the expected results, I am looking to know how to calculate them. I think my doubt is here : given that I have two points on the X axis of the new CS,  I suppose that I should calculate the angles of this vector with global axis and plus the translations ( if they happened in CS transformation). but then for the rotation matrix, given that I know the first input,  how do I define the rotation order for rotation matrix ?


If I understand correctly what you mean this question/answer on stackexchange may help you [1].
Otherwise you need to better formalize your question to get a reply.
c.

[1] https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/897677#897677

Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-3


Il 21 nov 2019 12:26, Carlo De Falco <[hidden email]> ha scritto:


If I understand correctly what you mean this question/answer on stackexchange may help you [1].
Otherwise you need to better formalize your question to get a reply.
c.

[1] https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/897677#897677

And if you are OK with using homogeneous coordinates the problem discussed in that post can be simply implemented as

  T = vecrot (pi, (v + [1; 0; 0])/2)

Where I have assumed v is the name of the vector you want to align your x-axis with.

c.


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-3


> Il giorno 21 nov 2019, alle ore 13:01, Carlo de Falco <[hidden email]> ha scritto:
>
> T = vecrot (pi, (v + [1; 0; 0])/2)

use

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

if is not unitary.

c.






Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
Thank you very much dear Carlo and Crimson

I just have one problem : despite having installed the geometry package,  I get the error :  " vecrot is not defined"

On Thu, Nov 21, 2019 at 1:26 PM <[hidden email]> wrote:


> Il giorno 21 nov 2019, alle ore 13:01, Carlo de Falco <[hidden email]> ha scritto:
>
> T = vecrot (pi, (v + [1; 0; 0])/2)

use

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

if is not unitary.

c.






--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-3


> Il giorno 21 nov 2019, alle ore 13:40, Farzad Torabi <[hidden email]> ha scritto:
>
> Thank you very much dear Carlo and Crimson
>
vecrot i in the package "nurbs".
If you use windows most packages are alredy installed.
remember you need to load packages before you use them.
c.

Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
Thank you very much. yes that's true

but checking the docs about vecrot, it seems that it gives the rotation matrix with the angle Pi ( in case of your example) around vector v. Is it the same thing as what I indicated ? to transform the movements in a point according to global CS to movements(translations+rotations) according to a rotated CS ?




On Thu, Nov 21, 2019 at 1:55 PM <[hidden email]> wrote:


> Il giorno 21 nov 2019, alle ore 13:40, Farzad Torabi <[hidden email]> ha scritto:
>
> Thank you very much dear Carlo and Crimson
>
vecrot i in the package "nurbs".
If you use windows most packages are alredy installed.
remember you need to load packages before you use them.
c.


--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

nrjank
In reply to this post by Farzadtb


I just have one problem : despite having installed the geometry package,  I get the error :  " vecrot is not defined"


Did you load the package before trying to use it? 

>> pkg load geometry



Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
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 ?



On Thu, Nov 21, 2019 at 2:45 PM Nicholas Jankowski <[hidden email]> wrote:


I just have one problem : despite having installed the geometry package,  I get the error :  " vecrot is not defined"


Did you load the package before trying to use it? 

>> pkg load geometry



--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
I checked and if I am correct , the movements in global CS as

x= -5.1 , y=-6.7 , z = -9.9 , Rx=-0.9, Ry= -1.6 , Rz= -0.4

should give translations of 

x= -2.5712,  y= -12.702, z= 0.98144

I can't verify the rotations, but just want to see if these are correct

the new cs X vector is , as mentioned in the previous email : 

 [-115.830   -16.850   113.400]   


On Thu, Nov 21, 2019 at 2:55 PM Farzad Torabi <[hidden email]> wrote:
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 ?



On Thu, Nov 21, 2019 at 2:45 PM Nicholas Jankowski <[hidden email]> wrote:


I just have one problem : despite having installed the geometry package,  I get the error :  " vecrot is not defined"


Did you load the package before trying to use it? 

>> pkg load geometry



--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Francesco Potortì
In reply to this post by Farzadtb
>I need to convert the translations + rotations from global coordinate
>system into a new coordinate system that is translated+rotated from the
>global one. How do I obtain that ?

Load the 'image' package, and look at the tform functions:

        cp2tform
        maketform
        tformfwd
        tforminv

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
Thank you, I will check then, if you could please also indicate which one of these four you were intending? 

Farzad Torabi
Master in mechanical engineering

Il gio 21 nov 2019, 18:42 Francesco Potortì <[hidden email]> ha scritto:
>I need to convert the translations + rotations from global coordinate
>system into a new coordinate system that is translated+rotated from the
>global one. How do I obtain that ?

Load the 'image' package, and look at the tform functions:

        cp2tform
        maketform
        tformfwd
        tforminv

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Francesco Potortì
>> >I need to convert the translations + rotations from global coordinate
>> >system into a new coordinate system that is translated+rotated from the
>> >global one. How do I obtain that ?
>>
>> Load the 'image' package, and look at the tform functions:
>>
>>         cp2tform
>>         maketform
>>         tformfwd
>>         tforminv

>Thank you, I will check then, if you could please also indicate which one
>of these four you were intending?

Please answer below, not above, as is the custom of this list.

I used them long ago.  You read the help and you get it.  Essentially,
they are used for transforming a set of points in 2-D from5A one reference
system to a different one, with possible affine or projection
transformation.  You create a transformation matrix using maketform or
cp2tform and give this matrix as argument to either tformfwd or tforminv
depending on the transformation direction.

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it


Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Carlo de Falco-3
In reply to this post by Farzadtb


> Il giorno 21 nov 2019, alle ore 14:55, Farzad Torabi <[hidden email]> 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




















Reply | Threaded
Open this post in threaded view
|

Re: Rotation matrix definition

Farzadtb
Thank you very much

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 ?

On Fri, Nov 22, 2019 at 12:35 PM <[hidden email]> wrote:


> Il giorno 21 nov 2019, alle ore 14:55, Farzad Torabi <[hidden email]> 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




















--
SeyedFarzad Torabi
Master of Mech. Eng.
Politecnico Di Milano


12