# 关于求解euler角的问题

``````6-DoF rigid body motion
Centre of rotation: (5 0.45 0.9)
Centre of mass: (5 0.45 0.9)
Orientation: (0.995589999257 0 -0.09381126467 0 1 0 0.09381126467 0 0.995589999257)
Linear velocity: (0 0 0)
Angular velocity: (0 -0.21652336234 -0)
``````

``````      quaternion b = quaternion(orientation());
vector ang = b.eulerAngles(b);
Info<< " Euler angles: " << 180/3.14159265359*ang << endl; //- Print the angle vector
``````

``````6-DoF rigid body motion
Centre of rotation: (-0.5 0.449998563721 0.1)
Centre of mass: (-0.500001532453 0.449998563721 0.349999999995)
Orientation: (0.999999999981 0 -6.1298114399e-06 0 1 0 6.1298114399e-06 0 0.999999999981)
Linear velocity: (0 -5.227784072e-05 0)
Angular velocity: (0 -0.000462275194671 0)
Euler angles: (0 -0.000351212324719 0)
``````

sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:333:33: error: no matching function for call to ‘Foam::quaternion::eulerAngles(Foam::quaternion&)’

``````    quaternion b = quaternion(orientation());
enum eulerOrder A;
A = ZXY;
vector ang = b.eulerAngles(A);
Info<< " Euler angles: " << 180/3.14159265359*ang << endl; //- Print the angle vector
``````

ZXY 是欧拉角的坐标旋转顺序，按你的情况修改。

``````sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C: In member function ‘void Foam::sixDoFRigidBodyMotion::status() const’: sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:340:35: error: no matching function for call to ‘Foam::quaternion::eulerAngles(Foam::quaternion&)’
vector ang = b.eulerAngles(b);
^
In file included from /root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/quaternion.H:317:0,
from /root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/septernion.H:48,
from sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:31:
/root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/quaternionI.H:407:21: note: candidate: Foam::vector Foam::quaternion::eulerAngles(Foam::quaternion::eulerOrder) const
inline Foam::vector Foam::quaternion::eulerAngles
^~~~
/root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/quaternionI.H:407:21: note:   no known conversion for argument 1 from ‘Foam::quaternion’ to ‘Foam::quaternion::eulerOrder’
/root/OpenFOAM/OpenFOAM-v1912/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o' failed
make: *** [Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o] Error 1

``````

``````sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C: In member function ‘void Foam::sixDoFRigidBodyMotion::status() const’:
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:340:12: error: use of enum ‘eulerOrder’ without previous declaration
enum eulerOrder A;
^~~~~~~~~~
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:341:11: error: ‘ZXY’ was not declared in this scope
A = ZXY;
^~~
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:342:35: error: invalid conversion from ‘int’ to ‘Foam::quaternion::eulerOrder’ [-fpermissive]
vector ang = b.eulerAngles(A);
^
In file included from /root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/quaternion.H:317:0,
from /root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/septernion.H:48,
from sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:31:
/root/OpenFOAM/OpenFOAM-v1912/src/OpenFOAM/lnInclude/quaternionI.H:407:21: note:   initializing argument 1 of ‘Foam::vector Foam::quaternion::eulerAngles(Foam::quaternion::eulerOrder) const’
inline Foam::vector Foam::quaternion::eulerAngles
^~~~
/root/OpenFOAM/OpenFOAM-v1912/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o' failed
make: *** [Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o] Error 1
``````

``````        //- Euler-angle rotation order
enum eulerOrder : unsigned char
{
// Proper Euler angles
XZX, XYX, YXY, YZY, ZYZ, ZXZ,

// Tait-Bryan angles
XZY, XYZ, YXZ, YZX, ZYX, ZXY
};

//- The names for Euler-angle rotation order
static const Enum<eulerOrder> eulerOrderNames;
·
·
·
//- Construct from three Euler rotation angles
inline quaternion(const eulerOrder order, const vector& angles);
·
·
·

//- Return the Euler rotation angles corresponding to the
//- specified rotation order
inline vector eulerAngles(const eulerOrder order) const;
``````

``````        //- Construct a quaternion given the three Euler angles
inline quaternion
(
const scalar angleX,
const scalar angleY,
const scalar angleZ
);
·
·
·
//  the x, y and z axes.
inline vector eulerAngles(const quaternion& q) const;

``````

``````    quaternion b = quaternion(orientation());
eulerOrder A;
A = ZXY;
vector ang = b.eulerAngles(A);
Info<< " Euler angles: " << 180/3.14159265359*ang << endl; //- Print the angle vector
``````

``````sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C: In member function ‘void Foam::sixDoFRigidBodyMotion::status() const’:
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:333:5: error: ‘eulerOrder’ was not declared in this scope
eulerOrder A;
^~~~~~~~~~
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:334:5: error: ‘A’ was not declared in this scope
A = ZXY;
^
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:334:9: error: ‘ZXY’ was not declared in this scope
A = ZXY;
^~~
/root/OpenFOAM/OpenFOAM-v1812/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o' failed
make: *** [Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o] Error 1
``````

v1912 上的定义不一样，提示跟变量定义范围有关。

``````sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C: In member function ‘void Foam::sixDoFRigidBodyMotion::status() const’:
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:333:2: error: ‘eulerOrder’ was not declared in this scope
^~~~~~~~~~
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:334:2: error: ‘A’ was not declared in this scope
^
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:334:6: error: ‘ZXY’ was not declared in this scope
^~~
/root/OpenFOAM/OpenFOAM-v1812/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o' failed
make: *** [Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o] Error 1
``````

``````void Foam::sixDoFRigidBodyMotion::status() const
{
Info<< "6-DoF rigid body motion" << nl
<< "    Centre of rotation: " << centreOfRotation() << nl
<< "    Centre of mass: " << centreOfMass() << nl
<< "    Orientation: " << orientation() << nl
<< "    Linear velocity: " << v() << nl
<< "    Angular velocity: " << omega()
<< endl;
Info<< " Euler angles: " << 180/3.14159265359*ang << endl; //- Print the angle vector
}
``````

``````void Foam::sixDoFRigidBodyMotion::status() const
{
rotationSequence A(ZXY);
Info<< "6-DoF rigid body motion" << nl
<< "    Centre of rotation: " << centreOfRotation() << nl
<< "    Centre of mass: " << centreOfMass() << nl
<< "    Orientation: " << orientation() << nl
<< "    Linear velocity: " << v() << nl
<< "    Angular velocity: " << omega() << nl
<< "    Euler Angles: " << quaternion(orientation()).eulerAngles(A)
<< endl;
}
``````

``````    //- Euler-angle rotation sequence
enum rotationSequence
{
ZYX, ZYZ, ZXY, ZXZ, YXZ, YXY, YZX, YZY, XYZ, XYX, XZY, XZX
}
``````

``````sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C: In member function ‘void Foam::sixDoFRigidBodyMotion::status() const’:
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:325:5: error: ‘rotationSequence’ was not declared in this scope
rotationSequence A(ZXY);
^~~~~~~~~~~~~~~~
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:325:5: note: suggested alternative: ‘rotationTensorX’
rotationSequence A(ZXY);
^~~~~~~~~~~~~~~~
rotationTensorX
sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.C:332:64: error: ‘A’ was not declared in this scope
<< " Euler angles: " << quaternion(orientation()).eulerAngles(A)
^
/root/OpenFOAM/OpenFOAM-v1812/wmake/rules/General/transform:34: recipe for target 'Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o' failed
make: *** [Make/linux64GccDPInt32Opt/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionAngle.o] Error 1
``````

``````void Foam::sixDoFRigidBodyMotion::status() const
{
Info<< "6-DoF rigid body motion" << nl
<< "    Centre of rotation: " << centreOfRotation() << nl
<< "    Centre of mass: " << centreOfMass() << nl
<< "    Orientation: " << orientation() << nl
<< "    Linear velocity: " << v() << nl
<< "    Angular velocity: " << omega() << nl
<< "    Euler angles: " << quaternion(orientation()).eulerAngles(quaternion::eulerOrder::ZXY)
<< endl;
}
``````

1 Like

``````void Foam::sixDoFRigidBodyMotion::status() const
{
Info<< "6-DoF rigid body motion" << nl
<< "    Centre of rotation: " << centreOfRotation() << nl
<< "    Centre of mass: " << centreOfMass() << nl
<< "    Orientation: " << orientation() << nl
<< "    Linear velocity: " << v() << nl
<< "    Angular velocity: " << omega() << nl
<< " Euler angles: " << quaternion(orientation()).eulerAngles(quaternion::rotationSequence::ZXY)
<< endl;
}

``````

1 Like