Reputation: 1360
I'm trying to understand the transformation between euler angles and rotation matrix.
Simulating random matrix of euler angles and the transformed them into 3D rotation matrix and back to euler angles do not preserve the original euler angles.
import tensorflow as tf
import tensorflow.experimental.numpy as tfnp
import tensorflow_graphics as tfg
tf.random.set_seed(5)
n = 10
euler = tf.random.uniform(shape=[n, 3], minval=-tfnp.pi, maxval=tfnp.pi, seed=0)
R = tfg.geometry.transformation.rotation_matrix_3d.from_euler(euler)
euler_ = tfg.geometry.transformation.euler.from_rotation_matrix(R)
print(tf.math.reduce_mean(tf.abs(euler - euler_)))
output:
tf.Tensor(1.5279251, shape=(), dtype=float32)
However when repeating this transformation again, now with euler_
instead of euler
as input, yield identical euler angles (up to numerical precision)
R_ = tfg.geometry.transformation.rotation_matrix_3d.from_euler(euler_)
euler__ = tfg.geometry.transformation.euler.from_rotation_matrix(R_)
print(tf.reduce_mean(tf.abs(euler_ - euler__)))
output:
tf.Tensor(6.417433e-07, shape=(), dtype=float32)
My question is why in the first transformation the euler angle do not preserved while in the second transformation they do preserved?
Upvotes: 0
Views: 368
Reputation: 1360
The point is that there are two valid solutions for decomposiotn a rotation matrix into two different euler angles.
For example the yaw angle of the two soultions is realted with (since
)
For more detail see this exclent summary Computing Euler angles from a rotation matrix
Upvotes: 0