In the physics engine I am using, joint rotation frames are defined with quaternions. I would like to find the relative angle of the jointed child to its parent body.
I tried converting the difference rotation to Euler angles:
let rotation = transform.rotation.mul_quat(joint.data.local_basis2());
let parent_rotation = parent_transform
.rotation
.mul_quat(joint.data.local_basis1());
let difference = parent_rotation.inverse().mul_quat(rotation).normalize();
let (x, y, z) = difference.to_euler(EulerRot::XYZ);
But this does not provide me with what I'm looking for. The angles returned in some axes depend on the angle in other axes, depending on the order of to_euler conversion defined by EulerRot. Moreover, one of the angles is in the range of -90 to 90. In the XYZ case, when the Y euler angle reaches 90 or -90 degrees, it starts going back towards 0 with further rotation of the body.
Quaternion to matrix rotation only one axis
This solution on the other hand has strange X and Z angles when Y passes through 0 and 180 degrees. They appear to blow up for a moment then go back down to reasonable numbers.
This is all done with a child body dangling about the X and Z angles, while I roll it around the Y.
What I would like to find are rotations along every axis in range of -180 to 180, so that I can determine how to react based on how far the joint has pitched, yawed and rolled. Alternatively, maybe there is a way to determine that without converting to angles and use the given quaternions or transformation matrices available in the engine?