MantisBT - Community
View Issue Details
0025574Community[OCCT] OCCT:Foundation Classespublic2014-12-09 14:122016-04-20 15:49
BenjaminBihler 
abv 
normalmajor 
closedfixed 
LinuxDebian 6.032 bit
[OCCT] 6.8.0 
[OCCT] 7.0.0[OCCT] 7.0.0 
bugs fclasses bug25574
0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
If I perform a Y-P-R rotation by hand and afterwards create a displacement transformation from the origin to the target of the rotation, I would expect it to give me the Euler angles that I have used for the rotation. It doesn't. The values differ.

Please see the code below.
#include <gp_Quaternion.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>

void testEulerAngleRotation()
{
    // Start with world coordinate system
    gp_Ax2 world;

    // Perform three rotations using the yaw-pitch-roll convention.
    // This means: rotate around the original z axis with angle alpha,
    // then rotate around the new y axis with angle beta,
    // then rotate around the new x axis with angle gamma.
    Standard_Real alpha = 0.0 / 180.0 * M_PI;
    Standard_Real beta = -35.0 / 180.0 * M_PI;
    Standard_Real gamma = 90.0 / 180.0 * M_PI;

    const gp_Quaternion rotationZ(world.Direction(), alpha);
    const gp_Vec rotY = rotationZ.Multiply(world.YDirection());
    const gp_Vec rotX = rotationZ.Multiply(world.XDirection());

    const gp_Quaternion rotationY(rotY, beta);
    const gp_Vec rotZ = rotationY.Multiply(world.Direction());
    const gp_Vec rotRotX = rotationY.Multiply(rotX);

    const gp_Quaternion rotationX(rotRotX, gamma);
    const gp_Vec rotRotZ = rotationX.Multiply(rotZ);

    gp_Ax2 result(gp_Pnt(0.0, 0.0, 0.0), rotRotZ, rotRotX);

    // Now compute the Euler angles
    gp_Trsf transformation;
    transformation.SetDisplacement(gp_Ax2(), result);

    Standard_Real computedAlpha;
    Standard_Real computedBeta;
    Standard_Real computedGamma;

    transformation.GetRotation().GetEulerAngles(gp_YawPitchRoll, computedAlpha,
            computedBeta, computedGamma);

    // We expect now to get the same angles as we have used for our rotations
    std::cout << "alpha: " << alpha / M_PI * 180.0 << " and computed alpha: "
            << computedAlpha / M_PI * 180.0 << std::endl;
    std::cout << "beta: " << beta / M_PI * 180.0 << " and computed beta: "
            << computedBeta / M_PI * 180.0 << std::endl;
    std::cout << "gamma: " << gamma / M_PI * 180.0 << " and computed gamma: "
            << computedGamma / M_PI * 180.0 << std::endl;
}
No tags attached.
related to 0025946closed shoogen extrinsic Euler conventions in gp_Quaternion 
Issue History
2014-12-09 14:12BenjaminBihlerNew Issue
2014-12-09 14:12BenjaminBihlerAssigned To => abv
2014-12-09 17:09shoogenNote Added: 0035226
2014-12-09 17:50BenjaminBihlerNote Added: 0035229
2014-12-09 17:50BenjaminBihlerNote Edited: 0035229bug_revision_view_page.php?bugnote_id=35229#r8813
2015-03-19 22:05kgvRelationship addedrelated to 0025946
2015-04-19 19:11abvTarget Version => 6.9.0
2015-05-06 13:40gitNote Added: 0040615
2015-05-06 13:47abvNote Added: 0040618
2015-05-06 13:48abvTarget Version6.9.0 => 7.0.0
2015-06-11 10:54BenjaminBihlerNote Added: 0042102
2015-06-11 11:06abvNote Added: 0042103
2015-09-25 01:00abvAssigned Toabv => akz
2015-09-25 01:00abvStatusnew => assigned
2015-10-13 10:34gitNote Added: 0046687
2015-10-13 10:36akzNote Added: 0046688
2015-10-13 10:36akzAssigned Toakz => abv
2015-10-13 10:36akzStatusassigned => resolved
2015-10-13 10:36akzNote Edited: 0046688bug_revision_view_page.php?bugnote_id=46688#r11862
2015-10-13 10:36akzNote Edited: 0046688bug_revision_view_page.php?bugnote_id=46688#r11863
2015-10-13 12:20abvNote Added: 0046695
2015-10-13 12:20abvAssigned Toabv => akz
2015-10-13 12:20abvStatusresolved => assigned
2015-10-13 17:02gitNote Added: 0046709
2015-10-13 17:04akzNote Added: 0046710
2015-10-13 17:04akzAssigned Toakz => abv
2015-10-13 17:04akzStatusassigned => resolved
2015-10-13 17:04akzNote Edited: 0046710bug_revision_view_page.php?bugnote_id=46710#r11869
2016-01-22 13:06gitNote Added: 0050048
2016-01-22 13:45abvNote Added: 0050050
2016-01-22 13:45abvAssigned Toabv => bugmaster
2016-01-22 13:45abvStatusresolved => reviewed
2016-01-22 15:04mkvAssigned Tobugmaster => mkv
2016-01-25 17:55mkvNote Added: 0050105
2016-01-25 17:55mkvTest case number => bugs fclasses bug25574
2016-01-25 17:56mkvNote Added: 0050106
2016-01-25 17:56mkvAssigned Tomkv => bugmaster
2016-01-25 17:56mkvStatusreviewed => tested
2016-01-29 12:32bugmasterChangeset attached => occt master 4f5ad416
2016-01-29 12:32bugmasterStatustested => verified
2016-01-29 12:32bugmasterResolutionopen => fixed
2016-02-05 12:49abvChangeset attached => occt master 917cae00
2016-02-05 12:49abvAssigned Tobugmaster => abv
2016-04-17 13:18gitNote Added: 0052829
2016-04-17 13:18gitNote Added: 0052830
2016-04-17 13:18gitNote Added: 0052831
2016-04-17 13:18gitNote Added: 0052832
2016-04-20 15:43aivFixed in Version => 7.0.0
2016-04-20 15:49aivStatusverified => closed

Notes
(0035226)
shoogen   
2014-12-09 17:09   
Standard_Real gamma = 90.0 / 180.0 * M_PI;

using 90° in Eulerian angles sounds like a bad idea to me.
Are you sure that you did not hit a Gimbal lock?
(0035229)
BenjaminBihler   
2014-12-09 17:50   
When working with robots it is quite usual to use 90° in Euler angles.

But I have changed the values in the given code to 10°, 20° and 30°. It is the same: the computed values differ from the actual rotation angles.

Another case:

If I set
alpha = 0°
beta = 0°
gamma = 10°,
I get
computed alpha = 10°
computed beta = 0°
computed gamma = 0°.

Such things (same values but other order) happen normally, when using wrong Euler sequences. According to my understanding, I am using the correct sequence for YPR rotations (Z, Y', X''). If I was right, the OCC computation would be wrong - probably not wrong at all, but somehow using the wrong Euler sequence...

(0040615)
git   
2015-05-06 13:40   
Branch CR25574 has been created by abv.

SHA-1: 8f92b6612f59e0e615bb12c911a70d910da7121a


Detailed log of new commits:

Author: abv
Date: Wed May 6 11:26:03 2015 +0300

    0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
    
    DRAW command CR25574 added for testing Euler angles sequences in gp_Quaternion
(0040618)
abv   
2015-05-06 13:47   
I confirm that, according to my testing, Euler sequences are not correctly applied in gp_Quaternion, alas. Have a look at DRAW command OCC25574 in the branch CR25574. It implements two checks:

- For each Euler sequence, convert some quaternion (currently taken from description of 0025946) to Euler angles and back, then check that resulting transformation is the same. This check seems to pass.

- For each Euler sequence, check that rotation by each single angle does not affect vector located on corresponding axis. This check fails for most sequences, however gp_YawPitchRoll (gp_Intrinsic_ZYX) is among the few looking fine...

This is to be further investigated, any comments are welcome.

Note that patch on 0025946 proposed by shoogen does not help.
(0042102)
BenjaminBihler   
2015-06-11 10:54   
Since this issue has been open for half a year now, I would like to share my workaround with you. Orocos KDL (http://www.orocos.org/kdl [^]) also has an implementation of Euler ZYX and Euler ZYZ rotations which are the most important ones when using robots. Since I have been using Orocos KDL anyway, I have switched to their implementation which works correctly.

So for me it is not necessary anymore that this bug is fixed in OCC. Still I would very much appreciate if at least the functionality was removed. Then there is no danger anymore that anyone spends as much time as I did trying to use buggy methods.
(0042103)
abv   
2015-06-11 11:06   
Benjamin, we will address the issue and correct OCCT code as soon as we have time. Note that you can contribute the fix if you know how this should be corrected.
(0046687)
git   
2015-10-13 10:34   
Branch CR25574_1 has been created by akz.

SHA-1: 9f11ec99741a0ad5d6a7dea9936969d8aefcfcda


Detailed log of new commits:

Author: akz
Date: Tue Oct 13 10:30:52 2015 +0300

    0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
    
    Fixes incorrect parametrization for Quaterion <--> Euler angles conversion.
    Cause we use 3x3 rotation matrix as a middle step of conversion, we operate
    with fixed coordinate system, so all Intrinsic rotation should be converted
    to Extrinsic rotations.
(0046688)
akz   
2015-10-13 10:36   
Branch CR25574_1 is ready to review.
Also, this fix resolves 0025946 bug.

(0046695)
abv   
2015-10-13 12:20   
Anton, please add a test for Euler angles to ensure that calculations are correct (you can use command I pushed to branch CR25574 some time ago as starting point)
(0046709)
git   
2015-10-13 17:02   
Branch CR25574_2 has been created by akz.

SHA-1: 825aeb2639bc79f056baf76599895a61eddb281b


Detailed log of new commits:

Author: akz
Date: Tue Oct 13 10:30:52 2015 +0300

    0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
    
    Fixes incorrect parametrization for Quaterion <--> Euler angles conversion.
    Cause we use 3x3 rotation matrix as a middle step of conversion, we operate
    with fixed coordinate system, so all Intrinsic rotation should be converted
    to Extrinsic rotations.
(0046710)
akz   
2015-10-13 17:04   
Andrey, I've added tests in QA command OCC25574. Please review branch CR25574_2.

(0050048)
git   
2016-01-22 13:06   
Branch CR25574_4 has been created by abv.

SHA-1: bd7cee22d738e30f579c4fc6836ae7837254b5a3


Detailed log of new commits:

Author: akz
Date: Tue Oct 13 10:30:52 2015 +0300

    0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
    
    Conversion of gp_Quaternion to and from intrinsic Tait-Bryan angles (including gp_YawPitchRoll) is fixed.
    
    Before that fix the sequence of rotation axes was opposite to intended; e.g. gp_YawPitchRoll (equivalent to gp_Intrinsic_ZYX) actually was defining intrinsic rotations around X, then Y, then Z.
    Now this is fixed, and rotations are made in correct order.
    
    Comments to gp_EulerSequence enumeration are restored (lost due to CDL extraction).
    
    Test bugs fclasses bug25574 is added to check correctness of Euler sequences, including cases from 0025574 and 0025946.
(0050050)
abv   
2016-01-22 13:45   
Fix reviewed and completed (added more details in description, note in upgrade documentation, test case, restored comments to gp_EulerSequence enum).

Please check compilation and new test case (bugs fclasses bug25574). Note that overall testing is not needed, since gp_Quaternion is not (yet) used in other OCCT components.
(0050105)
mkv   
2016-01-25 17:55   
Dear BugMaster,
Branch CR25574_4 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested on Release mode.
SHA-1: bd7cee22d738e30f579c4fc6836ae7837254b5a3

Number of compiler warnings:

occt component :
Linux: 0 (0 on master)
Windows: 0 (0 on master)
MacOS : 1 (1 on master)

products component :
Linux: 36 (36 on master)
Windows: 0 (0 on master)

Regressions/Differences/Improvements:
No regressions/differences

Testing cases:
http://occt-tests/CR25574-4-master-occt-64/Debian70-64/bugs/fclasses/bug25574.html [^]
http://occt-tests/CR25574-4-master-occt-64/Windows-64-VC10/bugs/fclasses/bug25574.html [^]
bugs fclasses bug25574: OK

Testing on Linux:
occt component :
Total MEMORY difference: 89634546 / 89612607 [+0.02%]
Total CPU difference: 19100.99999999999 / 19155.6700000001 [-0.29%]
products component :
Total MEMORY difference: 25648679 / 25586674 [+0.24%]
Total CPU difference: 8391.089999999984 / 8527.089999999978 [-1.59%]

Testing on Windows:
occt component :
Total MEMORY difference: 57244699 / 57250493 [-0.01%]
Total CPU difference: 17808.294154998952 / 18418.882068999024 [-3.32%]
products component :
Total MEMORY difference: 17257139 / 17270013 [-0.07%]
Total CPU difference: 5751.959671299985 / 6201.835355099963 [-7.25%]

There are no differences in images found by testdiff.
(0050106)
mkv   
2016-01-25 17:56   
Dear BugMaster,
Branch CR25574_4 is TESTED.
(0052829)
git   
2016-04-17 13:18   
Branch CR25574 has been deleted by kgv.

SHA-1: 8f92b6612f59e0e615bb12c911a70d910da7121a
(0052830)
git   
2016-04-17 13:18   
Branch CR25574_1 has been deleted by kgv.

SHA-1: 9f11ec99741a0ad5d6a7dea9936969d8aefcfcda
(0052831)
git   
2016-04-17 13:18   
Branch CR25574_2 has been deleted by kgv.

SHA-1: 825aeb2639bc79f056baf76599895a61eddb281b
(0052832)
git   
2016-04-17 13:18   
Branch CR25574_4 has been deleted by kgv.

SHA-1: bd7cee22d738e30f579c4fc6836ae7837254b5a3