MCPcopy Create free account
hub / github.com/ChristopherLu/milliEgo / euler2mat

Function euler2mat

eulerangles.py:94–191  ·  view source on GitHub ↗

Return matrix for rotations around z, y and x axes Uses the z, then y, then x convention above Parameters ---------- z : scalar Rotation angle in radians around z-axis (performed first) y : scalar Rotation angle in radians around y-axis x : scalar Rota

(z=0, y=0, x=0)

Source from the content-addressed store, hash-verified

92
93
94def euler2mat(z=0, y=0, x=0):
95 ''' Return matrix for rotations around z, y and x axes
96
97 Uses the z, then y, then x convention above
98
99 Parameters
100 ----------
101 z : scalar
102 Rotation angle in radians around z-axis (performed first)
103 y : scalar
104 Rotation angle in radians around y-axis
105 x : scalar
106 Rotation angle in radians around x-axis (performed last)
107
108 Returns
109 -------
110 M : array shape (3,3)
111 Rotation matrix giving same rotation as for given angles
112
113 Examples
114 --------
115 >>> zrot = 1.3 # radians
116 >>> yrot = -0.1
117 >>> xrot = 0.2
118 >>> M = euler2mat(zrot, yrot, xrot)
119 >>> M.shape == (3, 3)
120 True
121
122 The output rotation matrix is equal to the composition of the
123 individual rotations
124
125 >>> M1 = euler2mat(zrot)
126 >>> M2 = euler2mat(0, yrot)
127 >>> M3 = euler2mat(0, 0, xrot)
128 >>> composed_M = np.dot(M3, np.dot(M2, M1))
129 >>> np.allclose(M, composed_M)
130 True
131
132 You can specify rotations by named arguments
133
134 >>> np.all(M3 == euler2mat(x=xrot))
135 True
136
137 When applying M to a vector, the vector should column vector to the
138 right of M. If the right hand side is a 2D array rather than a
139 vector, then each column of the 2D array represents a vector.
140
141 >>> vec = np.array([1, 0, 0]).reshape((3,1))
142 >>> v2 = np.dot(M, vec)
143 >>> vecs = np.array([[1, 0, 0],[0, 1, 0]]).T # giving 3x2 array
144 >>> vecs2 = np.dot(M, vecs)
145
146 Rotations are counter-clockwise.
147
148 >>> zred = np.dot(euler2mat(z=np.pi/2), np.eye(3))
149 >>> np.allclose(zred, [[0, -1, 0],[1, 0, 0], [0, 0, 1]])
150 True
151 >>> yred = np.dot(euler2mat(y=np.pi/2), np.eye(3))

Callers 1

convert_rel_to_44matrixFunction · 0.90

Calls

no outgoing calls

Tested by 1

convert_rel_to_44matrixFunction · 0.72