How would one be able to clamp a quaternion based on the angle relative to a plane surface (defined by a normal)?
My diagram below provides more of a visual explanation of exactly what I am talking about.
The quaternions are clamped based on theirthe angle between the planes surface, and the quaternionquaternion's forward vector (i.e. q * (0, 0, 1)
). The quaternions are global quaternions. The plane normal (vector) N defines the upwards direction of the plane surface. Angles that go opposite of the normal vector is negative, whereas in the direction is positive. With that in mind, the quaternion's angle cannot be greater than MAX degrees and less than MIN degrees. These bounds are visualized by the cones (MIN is -90˚ in the diagram, so the cone is infinitely thin).
Thoughts:
My thought is that this algorithm would have to work in regards to the quaternions delta (unless the quaternion is in the MIN/MAX zones, which I will talk about later). If the change (delta) of the quaternion results in the quaternion entering, or passing, the bounds, the change is capped (clamped) so the final quaternion never has a resulting angle that dissatisfy the bounds.
Clamping the delta could be achieved by determining the beginning and end angles, and obtaining a ratio to be used as the t value (the interpolator) of a Slerp function, so the final quaternion's angle is that of the bound. The issue I see with this is how the roll would be manipulated due to the Slerp. Would the intended, final roll of the quaternion be lost due to this Slerping?
This idea of change seems more important in the example of if the quaternion was to go from -89˚ to -91˚. The final quaternion should be snapped back to -90˚ (if the bound was -90), instead of considering the new quaternion as -89˚ but from the other side. Without this proper interpretation of the quaternion's angle, the quaternion could rotate around constantly and consistently due to the angle never being considered less than -90˚ and greater than 90˚.
Edge Case:
If the quaternion was to start inside the MIN/MAX zones (the cones), the quaternion would not have a change to define as the direction that the quaternion needs to move to get back to legal territory/angles (see angle a3 in diagram). My thoughts is that a fallback plane normal that is orthogonal to plane normal N would have to be used, so the quaternion has a plane to rotate around.
Use Case:
Orbiting camera with user or author definable pitch angle clamping, and a varying change in "up". Example of varying change of "up": Mario Kart 8 Deluxe.