Rotation¶
Euler angles¶
Extrinsic Rotation¶
Right multiply matrix
In [1]:
import sympy
from sympy.vector import AxisOrienter, CoordSys3D
x, y, theta = sympy.symbols("x y theta")
N = CoordSys3D("N")
M = AxisOrienter(theta, N.k).rotation_matrix(N)
M
Out[1]:
$\displaystyle \left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)} & 0\\- \sin{\left(\theta \right)} & \cos{\left(\theta \right)} & 0\\0 & 0 & 1\end{matrix}\right]$
In [2]:
M.inv()
Out[2]:
$\displaystyle \left[\begin{matrix}- \frac{\sin^{2}{\left(\theta \right)}}{\cos{\left(\theta \right)}} + \frac{1}{\cos{\left(\theta \right)}} & - \sin{\left(\theta \right)} & 0\\\sin{\left(\theta \right)} & \cos{\left(\theta \right)} & 0\\0 & 0 & 1\end{matrix}\right]$
In [3]:
v = sympy.Matrix([x, y, 0]).T * M.subs(theta, sympy.pi/2)
v
Out[3]:
$\displaystyle \left[\begin{matrix}- y & x & 0\end{matrix}\right]$
In [4]:
import py3d
py3d.Transform.from_euler("xyz", [0.4, -0.2, 0])
Out[4]:
Transform([[ 0.98006658, 0. , 0.19866933, 0. ], [-0.07736548, 0.92106099, 0.3816559 , 0. ], [-0.18298657, -0.38941834, 0.9027011 , 0. ], [ 0. , 0. , 0. , 1. ]])
In [5]:
import py3d
axis=py3d.axis(dashed=True)
rotated_axis=py3d.axis()@py3d.Transform.from_euler("xyz", [1,2,3])
py3d.render(axis,rotated_axis)
Out[5]:
Intrinsic Rotation¶
In [6]:
import py3d
py3d.Transform.from_euler("XYZ", [0.4, -0.2, 0])
Out[6]:
Transform([[ 0.98006658, -0.07736548, 0.18298657, 0. ], [ 0. , 0.92106099, 0.38941834, 0. ], [-0.19866933, -0.3816559 , 0.9027011 , 0. ], [ 0. , 0. , 0. , 1. ]])
In [7]:
import py3d
py3d.Transform.from_rpy([1.3, 1.0, 0]) @ py3d.Transform.from_rpy([0.9, .0, 0])
Out[7]:
Transform([[ 0.54030231, 0.68032627, 0.49520661, 0. ], [ 0. , -0.58850112, 0.8084964 , 0. ], [ 0.84147098, -0.43683247, -0.31796851, 0. ], [ 0. , 0. , 0. , 1. ]])
Apply a intrinsic rotation to a point
In [9]:
import py3d
p = py3d.Vector3([1, 3, 4])
py3d.label("P", p.tolist())
py3d.render(p.as_point().paint(py3d.Color(g=1)))
t = py3d.Transform.from_euler("XYZ", [0, 0, 1])
p1 = p @ t
a = py3d.axis()
a.xyz @= t
py3d.label("P1", p1.tolist())
py3d.render(p1.as_point().paint(py3d.Color(r=1)), a)
Out[9]:
Difference between extrinsic rotation and intrinsic rotation¶
In [10]:
import py3d
e_car = py3d.car()
e_car.color = py3d.Color(g=1)
e_car.xyz @= py3d.Transform.from_euler("xyz", [0.4, -0.2, 0])
py3d.label("Extrincs", [4, 1, 3], color="green")
i_car = py3d.car()
i_car.color = py3d.Color(r=1)
i_car.xyz @= py3d.Transform.from_euler("XYZ", [0.4, -0.2, 0])
py3d.label("Intrincs", [4, -1, 2], color="red")
py3d.render(e_car, i_car)
Out[10]:
RPY¶
In py3d, rpy represents roll, pitch and yaw, it is kind of intrinsic rotation
In [11]:
from PIL import Image
import py3d, numpy
data = py3d.Vector(Image.open("20220917214012.jpg"))
data.as_image() @ py3d.Transform.from_rpy(p=numpy.linspace(0, py3d.pi/3, 3)) @ py3d.Transform.from_translation(z=numpy.linspace(0, 300, 3))
Out[11]: