# Coordinate system transformation problem (about Euler angle)

This question comes from the work that constructing the general cylinder by the NURBS. I have implemented the point-set $P_1,P_2,\cdots,P_n$ that in the $O-xyz$ plane, now I want to implement the point-set that in the plane $O_1-x_1y_1z_1$. So I need to transform the coordinate of $P_1,P_2,\cdots,P_n$ from the CS $O-xyz$ to CS $O_1-x_1y_1z_1$ firstly. Given that I have a set of points $P_1,P_2,\cdots,P_n$ in the $O-xyz$ plane. Please see the following schematic diagram. Here, $P_i=\{x_i,y_i,0\}$ Now I would like to transform these points to other coordinate system($O_1-x_1y_1z_1$). ### My trial

I believe that the key step is solving the transformation matrix between coordinate system ($O-xyz$) and coordinate system ($O_1-x_1y_1z_1$).

• Step1: Using the translational transformation $\begin{pmatrix} 1 && 0 && 0 && O_{1x}\\ 0 && 1 && 0 && O_{1y}\\ 0 && 0 && 1 && O_{1z}\\ 0 && 0 && 0 && 1 \end{pmatrix}$
• Step2: Using the composite rotational transformation. For the second step, I discovered the Euler-angle reference in Wiki-Encyclopedia. However, I didn't know how to confirm the angles like $\alpha$ and $\gamma$ via the $\vec{O_1z_1}=\{n_x,n_y,n_z\}$owing to that I am struggling to understand $\vec{N}$ axis.

For the angle $\beta$, it is easy to compute. Namely,

$$\cos\beta=\frac{n_z}{\sqrt{n_x^2+n_y^2+n_z^2}}$$

### Question

I have searched the DOC of Wolfram Mathematica by the keyword Euler in V9. Unfortunately, I cannot find the help info.

• Is there related built-in about Euler-angle transformation in Mathematica?
• Or how to do the Euler-angle transformation?
• V10 has EulerAngles... (not helpful if you are on V9). Have you searched the site yet (mathematica.stackexchange.com/search?q=euler+angle)? David Park´s addon contains Euler-related functions, too (which used to be free when I started out with Mathematica). Nov 21, 2015 at 10:41
• @YvesKlett, thanks. a lot :). Now searched the online DOC and then I discovered that EulerAngles[] was introduced in V10.2.
– xyz
Nov 21, 2015 at 10:47
• So you are on V10.2 or 10.3? Perhaps you can self-answer then... Nov 21, 2015 at 10:50

If you're just looking to re-orient your B-spline cylinder, there's no need to go through the Euler angles. Here's one way.

Consider the following cylinder:

myCyl = BSplineSurface[{{{0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}},
{{0, 0, 1}, {0, 1, 1}, {1, 1, 1}, {1, 0, 1}}},
SplineClosed -> {False, True}, SplineDegree -> {1, 3},
SplineWeights -> {{1, 3, 3, 1}, {1, 3, 3, 1}}];

Graphics3D[myCyl, Axes -> True] Note that this unit-height cylinder is pointing towards the positive $z$-axis. To re-orient this cylinder to point in a different direction, you can use RotationTransform[]. Here's how to re-orient it to point at the direction of $(3,1,2)$:

Graphics3D[{MapAt[Map[RotationTransform[{{0, 0, 1}, {3, 1, 2}}], #] &, myCyl, 1],
{Black, Arrow[Tube[{{0, 0, 0}, {3, 1, 2} // Normalize}]]}},
Axes -> True] You can of course add a translation:

Graphics3D[{MapAt[Map[Composition[TranslationTransform[{-1, -1, 1}],
RotationTransform[{{0, 0, 1}, {3, 1, 2}}]], #] &,
myCyl, 1],
{Black, Arrow[Tube[{{0, 0, 0}, {3, 1, 2} // Normalize}]]}},
Axes -> True] EulerMatrix is available in MMA 10. To obtain the matrix for the transformation shown in your sketch, apply

EulerMatrix[{α,β,γ},{3,1,3}]


This transformation is known as the x-convention, because the second rotation is about x'-axis. The Wikipedia designates this by ZXZ.

Those who do not have MMA 10 can obtain the same x-convention transformation using RotationMatrix applied 3 times. The code is

Transpose@
Dot[
RotationMatrix[γ, {0, 0, -1}],
RotationMatrix[β, {-1, 0, 0}],
RotationMatrix[α, {0, 0, -1}]]


As you know from the Wikipedia, there is more than one set of Euler angles. The y-convention is more common in quantum mechanics, so let me give that transformation here as well. In MMA 10, the y-convention transformation is

 EulerMatrix[{α,β,γ},{3,2,3}]


or

 EulerMatrix[{α,β,γ}]


since the y-convention is the default when the axes are not specified. The Wikipedia designates this by ZYZ. In terms of the RotationMatrix function, the y-convention transformation is

Transpose@
Dot[
RotationMatrix[γ, {0, 0, -1}],
RotationMatrix[β, {0, -1, 0}],
RotationMatrix[α, {0, 0, -1}]]


A reference for these transformations is Classical Mechanics by Herbert Goldstein, 2nd Edition, Section 4-4 and Appendix B.

• there is a vector {a,b,c}, after the rotation by ZYZ, the result is {a,b,c}.EulerMatrix[{α,β,γ},{3,2,3}] or EulerMatrix[{α,β,γ},{3,2,3}].{a,b,c} ? I found some textbook's rotation matrix is the inverse or transpose of the EulerMatrix[{α,β,γ}] in MMA using the same convention. Jun 29, 2016 at 1:04
• @Orders That is an excellent point. A matrix can rotate a vector, or it can rotate the coordinate system (CS). In MMA, the matrix m=EulerMatrix[{Pi/2,0,0},{3,2,3}] rotates the vector v around the plus Z-axis, or rotates the CS about the minus Z-axis. The matrix product r = m.v gives the components of the rotated vector r in the original CS, or gives components of the original vector in the rotated CS. Goldstein and others give the matrix that rotates the CS in the positive sense, which is the transpose of the matrix returned by EulerMatrix. I never ever use v.m. Jun 29, 2016 at 5:43

Suppose you have a vector p expressed as

p = p1 e1 + p2 e2 + p3 e3

where e1, e2, e3 are a dextral triad of unit vectors and p1, p2 and p3 are scalars.

Let n1, n2, n3 be another dextral triad of unit vectors.

Then p = p1 (e1.n1 n1 + e1.n2 n2 + e1.n3 n3) + p2 (e2.n1 n1 + e2.n2 n2 + e2.n3 n3) + p3 (e3.n1 n1 + e3.n2 n2 + e3.n3 n3)

You can collect terms to put this in the form p =()n1 + ()n2 + ()n3. The () contain scalars involving dot products.

e1.n1 is the cosine of the angle between e1 and n1. And similarly for the other 8.