# Rotation matrix definition Classic List Threaded 26 messages 12
Open this post in threaded view
|

## Rotation matrix definition

 Hi AllI 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 TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 > 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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 > 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  has a very extensive detailed explanation of rotation matrices.  https://en.wikipedia.org/wiki/Rotation_matrix#Multiplication
Open this post in threaded view
|

## Re: Rotation matrix definition

 dear CarloI 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  has a very extensive detailed explanation of rotation matrices.  https://en.wikipedia.org/wiki/Rotation_matrix#Multiplication-- SeyedFarzad TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 > 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 . Otherwise you need to better formalize your question to get a reply. c.  https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/897677#897677
Open this post in threaded view
|

## Re: Rotation matrix definition

 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 . Otherwise you need to better formalize your question to get a reply. c.  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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 > 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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 Thank you very much dear Carlo and CrimsonI 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 TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 > 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.
Open this post in threaded view
|

## Re: Rotation matrix definition

 Thank you very much. yes that's truebut 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 TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 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
Open this post in threaded view
|

## Re: Rotation matrix definition

 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 CSI 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 Vecotrbutinstead,  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.00000is 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 TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 I checked and if I am correct , the movements in global CS asx= -5.1 , y=-6.7 , z = -9.9 , Rx=-0.9, Ry= -1.6 , Rz= -0.4should give translations of x= -2.5712,  y= -12.702, z= 0.98144I can't verify the rotations, but just want to see if these are correctthe 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 CSI 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 Vecotrbutinstead,  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.00000is 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 TorabiMaster of Mech. Eng.Politecnico Di Milano -- SeyedFarzad TorabiMaster of Mech. Eng.Politecnico Di Milano
Open this post in threaded view
|

## Re: Rotation matrix definition

 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
Open this post in threaded view
|

## Re: Rotation matrix definition

 Thank you, I will check then, if you could please also indicate which one of these four you were intending? Farzad TorabiMaster 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
Open this post in threaded view
|

## Re: Rotation matrix definition

 >> >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
Open this post in threaded view
|