Question
How do you represent quaternion rotations in 2 dimensions?
I'm developing in Android Studio Java with two Bluetooth IMUs that give quaternions. The sensors are oriented in the following way to start:
In the image shown, this is considered the “zero” position. NOTE: XYZ is displayed on the sensors. This position should be represented on the phone screen like this:
The green circle represents the angular difference between the two sensors. This circle moves based on the orientation of the sensors. The orange circle is meant to be a target and therefore the distance between the two circles is the distance from being in line as shown in the zero position.
With these sensors I’m only concerned with two rotations for each of them. The red sensor rotates about Y and Z, whereas the blue sensor rotates about X and Y. Both of these sensors can rotate about the third axis, but I’m just not really concerned with it. If it’s absolutely necessary, these rotations could be represented by the black notch shown in the image above.
My question is how do I take the quaternions given by the sensors and represent them in 2 dimensions? So for example, a rotation like:
would be represented:
What I've tried: With the assistance of ChatGPT (since I’m somewhat new to quaternions still), I got this method, which moved the blue circle above the orange in it's zero. I’m not really sure of where CGPT got these conversions, but it’s what I have so far.
private PointF quaternionTo2D(Quaternion q) {
float angleX = (float) Math.atan2(2.0f * (q.w() * q.x() + q.y() * q.z()), 1.0f - 2.0f * (q.x() * q.x() + q.y() * q.y()));
float angleY = (float) Math.asin(2.0f * (q.w() * q.y() - q.z() * q.x())); // Mapping angles to screen coordinates
float x = (float) Math.sin(angleX); float y = (float) Math.sin(angleY);
Log.i("QuaternionTo2D", "Quaternion: " + q + " -> PointF: x=" + x + ", y=" + y);
return new PointF(x, y);
}
I'm feeding this method the relative rotation quaternion calculated by multiplying the conjugate of the red sensors quaternion by the blue sensors quaternion.
Any recommendations/tips are appreciated! I can also clarify any further details.