| Hosted by CoCalc | Download
(x, y, z) = var('theta_x, theta_y, theta_z') (sx, sy, sz) = (sin(x), sin(y), sin(z)) (cx, cy, cz) = (cos(x), cos(y), cos(z)) Rx = Matrix([ [1, 0, 0], [0, cos(x), -sin(x)], [0, sin(x), cos(x)] ]) Ry = Matrix([ [ cos(y), 0, sin(y)], [ 0, 1, 0], [-sin(y), 0, cos(y)] ]) Rz = Matrix([ [cos(z), -sin(z), 0], [sin(z), cos(z), 0], [ 0, 0, 1] ]) show( '$R_x=$', Rx, '$, R_y=$', Ry, '$, R_z=$', Rz ) show( '$R_x R_y R_z=$', Rx * Ry * Rz )
Rx=R_x= (1000cos(θx)sin(θx)0sin(θx)cos(θx))\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & \cos\left(\theta_{x}\right) & -\sin\left(\theta_{x}\right) \\ 0 & \sin\left(\theta_{x}\right) & \cos\left(\theta_{x}\right) \end{array}\right) ,Ry=, R_y= (cos(θy)0sin(θy)010sin(θy)0cos(θy))\displaystyle \left(\begin{array}{rrr} \cos\left(\theta_{y}\right) & 0 & \sin\left(\theta_{y}\right) \\ 0 & 1 & 0 \\ -\sin\left(\theta_{y}\right) & 0 & \cos\left(\theta_{y}\right) \end{array}\right) ,Rz=, R_z= (cos(θz)sin(θz)0sin(θz)cos(θz)0001)\displaystyle \left(\begin{array}{rrr} \cos\left(\theta_{z}\right) & -\sin\left(\theta_{z}\right) & 0 \\ \sin\left(\theta_{z}\right) & \cos\left(\theta_{z}\right) & 0 \\ 0 & 0 & 1 \end{array}\right)
RxRyRz=R_x R_y R_z= (cos(θy)cos(θz)cos(θy)sin(θz)sin(θy)cos(θz)sin(θx)sin(θy)+cos(θx)sin(θz)sin(θx)sin(θy)sin(θz)+cos(θx)cos(θz)cos(θy)sin(θx)cos(θx)cos(θz)sin(θy)+sin(θx)sin(θz)cos(θx)sin(θy)sin(θz)+cos(θz)sin(θx)cos(θx)cos(θy))\displaystyle \left(\begin{array}{rrr} \cos\left(\theta_{y}\right) \cos\left(\theta_{z}\right) & -\cos\left(\theta_{y}\right) \sin\left(\theta_{z}\right) & \sin\left(\theta_{y}\right) \\ \cos\left(\theta_{z}\right) \sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) + \cos\left(\theta_{x}\right) \sin\left(\theta_{z}\right) & -\sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) + \cos\left(\theta_{x}\right) \cos\left(\theta_{z}\right) & -\cos\left(\theta_{y}\right) \sin\left(\theta_{x}\right) \\ -\cos\left(\theta_{x}\right) \cos\left(\theta_{z}\right) \sin\left(\theta_{y}\right) + \sin\left(\theta_{x}\right) \sin\left(\theta_{z}\right) & \cos\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) + \cos\left(\theta_{z}\right) \sin\left(\theta_{x}\right) & \cos\left(\theta_{x}\right) \cos\left(\theta_{y}\right) \end{array}\right)
rXyz = Rx * Ry * Rz rZyx = Rz * Ry * Rx eberlyXyz = Matrix([ [ cy * cz, -(cy * sz), sy ], [ cz * sx * sy + cx * sz, cx * cz - sx * sy * sz, -(cy * sx)], [-(cx * cz * sy) + (sx * sz), cz * sx + cx * sy * sz, cx * cy ] ]) eberlyZyx = Matrix([ [cy*cz, (cz*sx*sy) - (cx*sz), cx*cz*sy + sx*sz ], [cy*sz, cx*cz + sx*sy*sz, -(cz*sx) + cx*sy*sz], [ -sy, cy*sx, cx*cy ] ]) unreal = Matrix([ [ cy * cz, cy * sz, sy ], [ sx * sy * cz - cx * sz, sx * sy * sz + cx * cz, -sx * cy], [-(cx * sy * cz + sx * sz), cz * sx - cx * sy * sz, cx * cy] ]) show( eberlyXyz - rXyz ) show( eberlyZyx - rZyx ) show( unreal - rXyz ) # #unreal = Matrix([ # [cy*cz, sx*sy*cz - cx*sz, -(cx*sy*cz + sx*sz) ], # [cy*sz, sx*sy*sz + cx*cz, cz*sx - cx*sy*sz], # [ sy, -(sx*cy), cx*cy ] #]) # #show( unreal - rZyx )
(000000000)\displaystyle \left(\begin{array}{rrr} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{array}\right)
(000000000)\displaystyle \left(\begin{array}{rrr} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{array}\right)
(02cos(θy)sin(θz)02cos(θx)sin(θz)2sin(θx)sin(θy)sin(θz)02sin(θx)sin(θz)2cos(θx)sin(θy)sin(θz)0)\displaystyle \left(\begin{array}{rrr} 0 & 2 \, \cos\left(\theta_{y}\right) \sin\left(\theta_{z}\right) & 0 \\ -2 \, \cos\left(\theta_{x}\right) \sin\left(\theta_{z}\right) & 2 \, \sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) & 0 \\ -2 \, \sin\left(\theta_{x}\right) \sin\left(\theta_{z}\right) & -2 \, \cos\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) & 0 \end{array}\right)
rXyzFlipz = Rx * Ry * Rz.inverse() show( unreal - rXyzFlipz )
((1cos(θz)sin(θz)2(sin(θz)2cos(θz)+cos(θz))cos(θz)2)cos(θy)+cos(θy)cos(θz)cos(θy)sin(θz)cos(θy)sin(θz)(sin(θz)2cos(θz)+cos(θz))cos(θz)0(1cos(θz)sin(θz)2(sin(θz)2cos(θz)+cos(θz))cos(θz)2)sin(θx)sin(θy)+cos(θz)sin(θx)sin(θy)cos(θx)sin(θz)+cos(θx)sin(θz)(sin(θz)2cos(θz)+cos(θz))cos(θz)sin(θx)sin(θy)sin(θz)+cos(θx)cos(θz)sin(θx)sin(θy)sin(θz)(sin(θz)2cos(θz)+cos(θz))cos(θz)cos(θx)sin(θz)2cos(θz)+cos(θz)0(1cos(θz)sin(θz)2(sin(θz)2cos(θz)+cos(θz))cos(θz)2)cos(θx)sin(θy)cos(θx)cos(θz)sin(θy)sin(θx)sin(θz)+sin(θx)sin(θz)(sin(θz)2cos(θz)+cos(θz))cos(θz)cos(θx)sin(θy)sin(θz)+cos(θz)sin(θx)+cos(θx)sin(θy)sin(θz)(sin(θz)2cos(θz)+cos(θz))cos(θz)sin(θx)sin(θz)2cos(θz)+cos(θz)0)\displaystyle \left(\begin{array}{rrr} -{\left(\frac{1}{\cos\left(\theta_{z}\right)} - \frac{\sin\left(\theta_{z}\right)^{2}}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)^{2}}\right)} \cos\left(\theta_{y}\right) + \cos\left(\theta_{y}\right) \cos\left(\theta_{z}\right) & \cos\left(\theta_{y}\right) \sin\left(\theta_{z}\right) - \frac{\cos\left(\theta_{y}\right) \sin\left(\theta_{z}\right)}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)} & 0 \\ -{\left(\frac{1}{\cos\left(\theta_{z}\right)} - \frac{\sin\left(\theta_{z}\right)^{2}}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)^{2}}\right)} \sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) + \cos\left(\theta_{z}\right) \sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) - \cos\left(\theta_{x}\right) \sin\left(\theta_{z}\right) + \frac{\cos\left(\theta_{x}\right) \sin\left(\theta_{z}\right)}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)} & \sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) + \cos\left(\theta_{x}\right) \cos\left(\theta_{z}\right) - \frac{\sin\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right)}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)} - \frac{\cos\left(\theta_{x}\right)}{\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)} & 0 \\ {\left(\frac{1}{\cos\left(\theta_{z}\right)} - \frac{\sin\left(\theta_{z}\right)^{2}}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)^{2}}\right)} \cos\left(\theta_{x}\right) \sin\left(\theta_{y}\right) - \cos\left(\theta_{x}\right) \cos\left(\theta_{z}\right) \sin\left(\theta_{y}\right) - \sin\left(\theta_{x}\right) \sin\left(\theta_{z}\right) + \frac{\sin\left(\theta_{x}\right) \sin\left(\theta_{z}\right)}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)} & -\cos\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right) + \cos\left(\theta_{z}\right) \sin\left(\theta_{x}\right) + \frac{\cos\left(\theta_{x}\right) \sin\left(\theta_{y}\right) \sin\left(\theta_{z}\right)}{{\left(\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)\right)} \cos\left(\theta_{z}\right)} - \frac{\sin\left(\theta_{x}\right)}{\frac{\sin\left(\theta_{z}\right)^{2}}{\cos\left(\theta_{z}\right)} + \cos\left(\theta_{z}\right)} & 0 \end{array}\right)
def QuatFromMatrix( m ): # wxyz, or rijk q = vector([1.0, 0.0, 0.0, 0.0]) q[0] = 0.5 * sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]) q[1] = (1.0 / 4.0 * q[0]) * (m[2][1] - m[1][2]) q[2] = (1.0 / 4.0 * q[0]) * (m[0][2] - m[2][0]) q[3] = (1.0 / 4.0 * q[0]) * (m[1][0] - m[0][1]) return q show( QuatFromMatrix( Rprod ) )
(0.707106781186548,0.000000000000000,0.000000000000000,0.000000000000000)\displaystyle \left(0.707106781186548,\,0.000000000000000,\,0.000000000000000,\,0.000000000000000\right)
show( (Rx * Ry * Rz).subs( x == 0, y == pi, z == 0 ) ) show( (Rz * Ry * Rx).subs( x == 0, y == pi, z == 0 ) )
(100010001)\displaystyle \left(\begin{array}{rrr} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & -1 \end{array}\right)
(100010001)\displaystyle \left(\begin{array}{rrr} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & -1 \end{array}\right)