Fri, 08/01/2025 - 12:16
I have loaded a STEP file into the viewer and selected the AIS_InteractiveObject representing a part. For that part, I attached an AIS_Manipulator to enable interactive rotation.
I enabled the rotation axis using:
AIS_ManipulatorMode::AIS_MM_Rotation
To perform rotation, I selected the axis and dragged it using the mouse. The rotation is applied via:
Manipulator->Transform(cx, cy, view);
where cx and cy are the current mouse coordinates.
To compute the transformation applied to the part, I used the following code:
Standard_Real angle;
gp_Trsf transformation = currentObject->Transformation();
gp_Quaternion quaternion = transformation.GetRotation();
angle = quaternion.GetRotationAngle();
angle = (angle * 180.0) / PI; // Convert radians to degrees
The values returned by GetRotationAngle() during interaction are as follows:
Observations:
When rotating clockwise, the angle values progress as:
0, 30, 60, 150, 180, -179, -150, -120, -90, -60, -20
When rotating counterclockwise, the angle values progress as:
0, 30, 60, 90, 120, -121, -150, -179, 180, 150, 120, 90, 60, 30
I observed that the angle sign flips after around ±120°, making the sequence discontinuous and harder to interpret.
Question:
Am I doing something wrong in this approach?
If not, what causes this sign change, and how can I avoid or correct it?
Fri, 08/01/2025 - 13:40
I don't think that
gp_Quaternion::GetRotationAngle()is of any use to you - at least in the way how you're trying to interprete it.Quaternion is a compact representation of 3D rotation defined by 4 values, and you cannot expect that a single value may adequately reflect it's definition for arbitrary rotations.
The rotations could be defined in many ways. One of the popular option is a triplet of Euler angles in user interface, which you may get via
gp_Quaternion::GetEulerAngles()method.In case if you want to display an exact rotation angle during
AIS_Manipulatorrotation operation, than you will need to take an active rotation axis from it and calculate rotation progress within this particular axis (but this will be only local rotation angle).