diff --git a/applications/test/quaternion/Test-quaternion.C b/applications/test/quaternion/Test-quaternion.C index 1f72daf5794939b90b398d68801c77407109bd44..1317ad4bf330258a72b0a5f72a32fa231cee1cab 100644 --- a/applications/test/quaternion/Test-quaternion.C +++ b/applications/test/quaternion/Test-quaternion.C @@ -47,14 +47,24 @@ using namespace Foam::coordinateRotations; void printRotation(const tensor& rot) { - Info<< "rotation = " << rot << nl; + Info<< "[\n" + << " " << rot.xx() << ' ' << rot.xy() << ' ' << rot.xz() << nl + << " " << rot.yx() << ' ' << rot.yy() << ' ' << rot.yz() << nl + << " " << rot.zx() << ' ' << rot.zy() << ' ' << rot.zz() << nl + << "]\n"; } void printRotation(const quaternion& quat) { - printRotation(quat.R()); - Info<< "quaternion " << quat << nl; + tensor rot(quat.R()); + + Info<< "quaternion " << quat << nl + << "rotation" << nl; + + printRotation(rot); + Info<< "transpose" << nl; + printRotation(rot.T()); } @@ -139,6 +149,12 @@ int main(int argc, char *argv[]) << " psi " << rotVector.z() << nl; printRotation(euler(rotVector, true).R()); + + rotVector *= degToRad(); + + const quaternion quat(quaternion::rotationSequence::ZXZ, rotVector); + + printRotation(quat); } if (args.readIfPresent("xyz", rotVector)) { diff --git a/src/meshTools/coordinate/rotation/EulerCoordinateRotation.C b/src/meshTools/coordinate/rotation/EulerCoordinateRotation.C index 41fa17f2ba313418fc7c606fcf7c0073a1f9d2fe..9964de1c60e78d8e04601c902b100c83ea458fee 100644 --- a/src/meshTools/coordinate/rotation/EulerCoordinateRotation.C +++ b/src/meshTools/coordinate/rotation/EulerCoordinateRotation.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010, 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -66,26 +66,24 @@ Foam::tensor Foam::coordinateRotations::euler::rotation bool degrees ) { - scalar phi = angles.component(vector::X); // 1. Rotate about Z - scalar theta = angles.component(vector::Y); // 2. Rotate about X - scalar psi = angles.component(vector::Z); // 3. Rotate about Z + scalar angle1(angles.component(vector::X)); // Rotation #1 + scalar angle2(angles.component(vector::Y)); // Rotation #2 + scalar angle3(angles.component(vector::Z)); // Rotation #3 if (degrees) { - phi *= degToRad(); - theta *= degToRad(); - psi *= degToRad(); + angle1 *= degToRad(); + angle2 *= degToRad(); + angle3 *= degToRad(); } - const scalar c1 = cos(phi); const scalar s1 = sin(phi); - const scalar c2 = cos(theta); const scalar s2 = sin(theta); - const scalar c3 = cos(psi); const scalar s3 = sin(psi); + const scalar c1(cos(angle1)); const scalar s1(sin(angle1)); + const scalar c2(cos(angle2)); const scalar s2(sin(angle2)); + const scalar c3(cos(angle3)); const scalar s3(sin(angle3)); - // Compare // https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix - // - // Z1-X2-Z3 rotation + // Z1-X2-Z3 rotation return tensor ( @@ -116,26 +114,26 @@ Foam::coordinateRotations::euler::euler(const euler& crot) Foam::coordinateRotations::euler::euler ( - const vector& phiThetaPsi, + const vector& angles, bool degrees ) : coordinateRotation(), - angles_(phiThetaPsi), + angles_(angles), degrees_(degrees) {} Foam::coordinateRotations::euler::euler ( - scalar phi, - scalar theta, - scalar psi, + scalar angle1, + scalar angle2, + scalar angle3, bool degrees ) : coordinateRotation(), - angles_(phi, theta, psi), + angles_(angle1, angle2, angle3), degrees_(degrees) {} diff --git a/src/meshTools/coordinate/rotation/EulerCoordinateRotation.H b/src/meshTools/coordinate/rotation/EulerCoordinateRotation.H index 2e436c96873350f991ca63fe72849650469be618..acba97903020b5bf5bd47f29ba0cebadd1bb0ec2 100644 --- a/src/meshTools/coordinate/rotation/EulerCoordinateRotation.H +++ b/src/meshTools/coordinate/rotation/EulerCoordinateRotation.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2011, 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -100,11 +100,11 @@ public: //- Copy construct euler(const euler& crot); - //- Construct from Euler rotation angles (z-x-z) - euler(const vector& phiThetaPsi, bool degrees); + //- Construct from Euler intrinsic rotation angles (z-x-z) + euler(const vector& angles, bool degrees); - //- Construct from Euler rotation angles (z-x-z) - euler(scalar phi, scalar theta, scalar psi, bool degrees); + //- Construct from Euler intrinsic rotation angles (z-x-z) + euler(scalar angle1, scalar angle2, scalar angle3, bool degrees); //- Construct from dictionary explicit euler(const dictionary& dict); @@ -124,8 +124,8 @@ public: // Static Member Functions - //- The rotation tensor calculated for the specified Euler angles - //- interpreted as phi/theta/psi (z-x-z order) + //- The rotation tensor calculated for the intrinsic Euler + //- angles in z-x-z order static tensor rotation(const vector& angles, bool degrees);