import sympy as sp
vy,vy,vz,theta,c,s,V = sp.symbols('vy vy vz theta c s V')
phi = sp.symbols('phi')
def Rx(theta,V):
"""
Rotation of a 3d vector V
of an angle theta around
the x-axis
"""
c = sp.cos(theta)
s = sp.sin(theta)
R = sp.Matrix(
[[1, 0, 0],
[0, c, -s],
[0, s, c]]
)
return R*V
V = sp.Matrix([[1],[2],[3]])
Rx(theta,V)
def Ry(theta,V):
"""
Rotation of a 3d vector V
of an angle theta around
the y-axis
"""
c = sp.cos(theta)
s = sp.sin(theta)
R = sp.Matrix(
[[c, 0, s],
[0, 1, 0],
[-s, 0, c]]
)
return R*V
def Rz(theta,V):
"""
Rotation of a 3d vector V
of an angle theta around
the z-axis
"""
c = sp.cos(theta)
s = sp.sin(theta)
R = sp.Matrix(
[[c, -s, 0],
[s, c, 0],
[0, 0, 1]]
)
return R*V
Rz(sp.pi/4,V)
def R(theta,phi,V):
"""
Rotation of a 3d vector V
of an angle theta around
the y-axis followed by a rotation
of phi around the z-axis
"""
return Rz(phi,Ry(theta,V))
Examples:
V = sp.Matrix([[1],[0],[0]])
R(theta,phi,V)
V = sp.Matrix([[0],[0],[1]])
R(theta,phi,V)
V = sp.Matrix([[1],[-sp.I],[0]])
R(theta,phi,V)
V = sp.Matrix([[-1],[-sp.I],[0]])
R(theta,phi,V)
V = sp.Matrix([[0],[0],[1]])
R(theta,phi,V)