SharedEulerMatrix.sagewsOpen in CoCalc

(x, y, z) = var('theta_x, theta_y, theta_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)

show( r'Given $$x=y=z= \frac{\pi}{2} $$, ')
show( '$Rx Ry Rz = Rxyz =$', Rx.subs( x == pi/2 ), Ry.subs( y == pi/2 ), Rz.subs( z == pi/2 ), '$=$', (Rx * Ry * Rz).subs( x == pi/2, y == pi/2, z == pi/2 ) )

Given x=y=z=π2x=y=z= \frac{\pi}{2} ,
RxRyRz=Rxyz=Rx Ry Rz = Rxyz = (100001010)\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 0 & -1 \\ 0 & 1 & 0 \end{array}\right) (001010100)\displaystyle \left(\begin{array}{rrr} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{array}\right) (010100001)\displaystyle \left(\begin{array}{rrr} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{array}\right) == (001010100)\displaystyle \left(\begin{array}{rrr} 0 & 0 & 1 \\ 0 & -1 & 0 \\ 1 & 0 & 0 \end{array}\right)

Vx = Matrix([ [1], [0], [0] ])
Vy = Matrix([ [0], [1], [0] ])
Vz = Matrix([ [0], [0], [1] ])

Rdev = Matrix([
    [0, 0, 1],
    [1, 0, 0],
    [0, 1, 0]
])

Rprod = Matrix([
    [0, 1,  0],
    [1, 0,  0],
    [0, 0, -1]
])

show( Rdev.det(), Rprod.det() )
1\displaystyle 1 1\displaystyle 1

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 ) )
(100010001)\displaystyle \left(\begin{array}{rrr} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & -1 \end{array}\right)