Euler angle access

This commit is contained in:
Hrvoje Jasak 2015-09-07 11:09:27 +01:00
parent 4d4c7d0eed
commit 5039ed9a30
4 changed files with 51 additions and 1 deletions

View file

@ -70,6 +70,33 @@ Foam::scalar Foam::finiteRotation::rotAngle(const tensor& rotT)
}
Foam::vector Foam::finiteRotation::eulerAngles(const tensor& rotT)
{
// Define a vector containing euler angles (x = roll, y = pitch, z = yaw)
vector eulerAngles;
scalar& rollAngle = eulerAngles.x();
scalar& pitchAngle = eulerAngles.y();
scalar& yawAngle = eulerAngles.z();
// Calculate roll angle
rollAngle = atan2(rotT.yz(), rotT.zz());
const scalar c2 = sqrt(rotT.xx() + rotT.xy());
// Calculate pitch angle
pitchAngle = atan2(-rotT.xz(), c2);
const scalar s1 = sin(rollAngle);
const scalar c1 = cos(rollAngle);
// Calculate yaw angle
yawAngle = atan2(s1*rotT.zx() - c1*rotT.yx(), c1*rotT.yy() - s1*rotT.zy());
return eulerAngles;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::finiteRotation::finiteRotation(const HamiltonRodriguezRot& rot)
@ -139,6 +166,12 @@ Foam::scalar Foam::finiteRotation::rotAngle() const
}
Foam::vector Foam::finiteRotation::eulerAngles() const
{
return eulerAngles(rotTensor_);
}
const Foam::tensor& Foam::finiteRotation::rotIncrementTensor() const
{
return rotIncrementTensor_;

View file

@ -69,6 +69,11 @@ class finiteRotation
//- Calculate rotation angle from given rotation tensor
static scalar rotAngle(const tensor& rotT);
//- Calculate Euler angles (x-y-z (roll-pitch-yaw) convenction) from
// given rotation tensor. Reference: Mike Day, Insomniac Games,
// Extracting Euler Angles from a Rotation Matrix.
static vector eulerAngles(const tensor& rotT);
public:
@ -110,6 +115,9 @@ public:
//- Return rotation angle
scalar rotAngle() const;
//- Return Euler angles (see static function eulerAngles for convention)
vector eulerAngles() const;
// Transformations between new and previous rotation
const tensor& rotIncrementTensor() const;

View file

@ -236,6 +236,9 @@ public:
//- Return average velocity of origin for the previous time-step
inline const dimensionedVector& Uaverage() const;
//- Return finite rotation
inline const finiteRotation& rotation() const;
//- Return acceleration of origin
inline dimensionedVector A() const;
@ -246,7 +249,7 @@ public:
inline dimensionedScalar rotAngle() const;
// Non-constant access to
// Non-constant access
//- Set position of origin
inline void setXrel(const vector& x);

View file

@ -172,6 +172,12 @@ const Foam::dimensionedVector& Foam::sixDOFqODE::Uaverage() const
}
const Foam::finiteRotation& Foam::sixDOFqODE::rotation() const
{
return rotation_;
}
Foam::vector Foam::sixDOFqODE::rotVectorAverage() const
{
return rotation_.rotVectorAverage();