View Issue Details

IDProjectCategoryView StatusLast Update
0025574CommunityOCCT:Foundation Classespublic2016-04-20 15:49
ReporterBenjaminBihler Assigned Toabv 
PrioritynormalSeveritymajor 
Status closedResolutionfixed 
PlatformLinuxOSDebian 6.0 
Product Version6.8.0 
Target Version7.0.0Fixed in Version7.0.0 
Summary0025574: gp_YawPitchRoll Euler Angle computation gives wrong results
DescriptionIf 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.
Steps To Reproduce#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;
}
TagsNo tags attached.
Test case numberbugs fclasses bug25574

Relationships

related to 0025946 closedshoogen extrinsic Euler conventions in gp_Quaternion 

Activities

shoogen

2014-12-09 17:09

reporter   ~0035226

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?

BenjaminBihler

2014-12-09 17:50

developer   ~0035229

Last edited: 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...

git

2015-05-06 13:40

administrator   ~0040615

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

abv

2015-05-06 13:47

manager   ~0040618

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.

BenjaminBihler

2015-06-11 10:54

developer   ~0042102

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.

abv

2015-06-11 11:06

manager   ~0042103

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.

git

2015-10-13 10:34

administrator   ~0046687

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.

akz

2015-10-13 10:36

developer   ~0046688

Last edited: 2015-10-13 10:36

Branch CR25574_1 is ready to review.
Also, this fix resolves 0025946 bug.

abv

2015-10-13 12:20

manager   ~0046695

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)

git

2015-10-13 17:02

administrator   ~0046709

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.

akz

2015-10-13 17:04

developer   ~0046710

Last edited: 2015-10-13 17:04

Andrey, I've added tests in QA command OCC25574. Please review branch CR25574_2.

git

2016-01-22 13:06

administrator   ~0050048

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.

abv

2016-01-22 13:45

manager   ~0050050

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.

mkv

2016-01-25 17:55

tester   ~0050105

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.

mkv

2016-01-25 17:56

tester   ~0050106

Dear BugMaster,
Branch CR25574_4 is TESTED.

git

2016-04-17 13:18

administrator   ~0052829

Branch CR25574 has been deleted by kgv.

SHA-1: 8f92b6612f59e0e615bb12c911a70d910da7121a

git

2016-04-17 13:18

administrator   ~0052830

Branch CR25574_1 has been deleted by kgv.

SHA-1: 9f11ec99741a0ad5d6a7dea9936969d8aefcfcda

git

2016-04-17 13:18

administrator   ~0052831

Branch CR25574_2 has been deleted by kgv.

SHA-1: 825aeb2639bc79f056baf76599895a61eddb281b

git

2016-04-17 13:18

administrator   ~0052832

Branch CR25574_4 has been deleted by kgv.

SHA-1: bd7cee22d738e30f579c4fc6836ae7837254b5a3

Related Changesets

occt: master 4f5ad416

2015-10-13 07:30:52

akz


Committer: bugmaster Details Diff
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.
Affected Issues
0025574
mod - dox/dev_guides/upgrade/upgrade.md Diff File
mod - src/gp/gp_EulerSequence.hxx Diff File
mod - src/gp/gp_Quaternion.cxx Diff File
mod - src/IVtkOCC/IVtkOCC_ViewerSelector.cxx Diff File
mod - src/QABugs/QABugs_19.cxx Diff File
add - tests/bugs/fclasses/bug25574 Diff File

occt: master 917cae00

2016-02-05 08:14:03

abv


Committer: abv Details Diff
0025574: gp_YawPitchRoll Euler Angle computation gives wrong results - warnings

Eliminate VC14 compiler warnings
Affected Issues
0025574
mod - src/BOPDS/BOPDS_Iterator.cxx Diff File
mod - src/QABugs/QABugs_19.cxx Diff File

Issue History

Date Modified Username Field Change
2014-12-09 14:12 BenjaminBihler New Issue
2014-12-09 14:12 BenjaminBihler Assigned To => abv
2014-12-09 17:09 shoogen Note Added: 0035226
2014-12-09 17:50 BenjaminBihler Note Added: 0035229
2014-12-09 17:50 BenjaminBihler Note Edited: 0035229
2015-03-19 22:05 kgv Relationship added related to 0025946
2015-04-19 19:11 abv Target Version => 6.9.0
2015-05-06 13:40 git Note Added: 0040615
2015-05-06 13:47 abv Note Added: 0040618
2015-05-06 13:48 abv Target Version 6.9.0 => 7.0.0
2015-06-11 10:54 BenjaminBihler Note Added: 0042102
2015-06-11 11:06 abv Note Added: 0042103
2015-09-25 01:00 abv Assigned To abv => akz
2015-09-25 01:00 abv Status new => assigned
2015-10-13 10:34 git Note Added: 0046687
2015-10-13 10:36 akz Note Added: 0046688
2015-10-13 10:36 akz Assigned To akz => abv
2015-10-13 10:36 akz Status assigned => resolved
2015-10-13 10:36 akz Note Edited: 0046688
2015-10-13 10:36 akz Note Edited: 0046688
2015-10-13 12:20 abv Note Added: 0046695
2015-10-13 12:20 abv Assigned To abv => akz
2015-10-13 12:20 abv Status resolved => assigned
2015-10-13 17:02 git Note Added: 0046709
2015-10-13 17:04 akz Note Added: 0046710
2015-10-13 17:04 akz Assigned To akz => abv
2015-10-13 17:04 akz Status assigned => resolved
2015-10-13 17:04 akz Note Edited: 0046710
2016-01-22 13:06 git Note Added: 0050048
2016-01-22 13:45 abv Note Added: 0050050
2016-01-22 13:45 abv Assigned To abv => bugmaster
2016-01-22 13:45 abv Status resolved => reviewed
2016-01-22 15:04 mkv Assigned To bugmaster => mkv
2016-01-25 17:55 mkv Note Added: 0050105
2016-01-25 17:55 mkv Test case number => bugs fclasses bug25574
2016-01-25 17:56 mkv Note Added: 0050106
2016-01-25 17:56 mkv Assigned To mkv => bugmaster
2016-01-25 17:56 mkv Status reviewed => tested
2016-01-29 12:32 bugmaster Changeset attached => occt master 4f5ad416
2016-01-29 12:32 bugmaster Status tested => verified
2016-01-29 12:32 bugmaster Resolution open => fixed
2016-02-05 12:49 abv Changeset attached => occt master 917cae00
2016-02-05 12:49 abv Assigned To bugmaster => abv
2016-04-17 13:18 git Note Added: 0052829
2016-04-17 13:18 git Note Added: 0052830
2016-04-17 13:18 git Note Added: 0052831
2016-04-17 13:18 git Note Added: 0052832
2016-04-20 15:43 aiv Fixed in Version => 7.0.0
2016-04-20 15:49 aiv Status verified => closed