ENH: use intermediate constants for sin/cos in coordinate rotations

- makes an easier overview of the rotation matrix coefficients
  (issue #863).

  Provided as a distinct commit for easier examination of the lines changed.
This commit is contained in:
Mark Olesen
2018-10-05 00:58:23 +02:00
parent b9c738dd10
commit e6a60f2de6
3 changed files with 22 additions and 29 deletions

View File

@ -65,20 +65,21 @@ Foam::tensor Foam::EulerCoordinateRotation::rotation
psi *= degToRad(); psi *= 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);
// Compare
// https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
// Z1-X2-Z3 rotation
return return
tensor tensor
( (
cos(phi)*cos(psi) - sin(phi)*sin(psi)*cos(theta), c1*c3 - c2*s1*s3, -c1*s3 - c2*c3*s1, s1*s2,
-sin(phi)*cos(psi)*cos(theta) - cos(phi)*sin(psi), c3*s1 + c1*c2*s3, c1*c2*c3 - s1*s3, -c1*s2,
sin(phi)*sin(theta), s2*s3, c3*s2, c2
cos(phi)*sin(psi)*cos(theta) + sin(phi)*cos(psi),
cos(phi)*cos(psi)*cos(theta) - sin(phi)*sin(psi),
-cos(phi)*sin(theta),
sin(psi)*sin(theta),
cos(psi)*sin(theta),
cos(theta)
); );
} }

View File

@ -32,14 +32,9 @@ Description
The order of the parameter arguments matches this rotation order. The order of the parameter arguments matches this rotation order.
For reference and illustration, see For reference and illustration, see
http://mathworld.wolfram.com/EulerAngles.html https://en.wikipedia.org/wiki/Euler_angles
and
https://en.wikipedia.org/wiki/Euler_angles#Conventions
Note, however, that it is the reverse transformation The rotation angles are in degrees, unless otherwise explicitly specified:
(local->global) that is defined here.
- the rotation angles are in degrees, unless otherwise explicitly specified:
\verbatim \verbatim
coordinateRotation coordinateRotation

View File

@ -166,20 +166,17 @@ Foam::tensor Foam::STARCDCoordinateRotation::rotation
z *= degToRad(); z *= degToRad();
} }
const scalar cx = cos(x); const scalar sx = sin(x);
const scalar cy = cos(y); const scalar sy = sin(y);
const scalar cz = cos(z); const scalar sz = sin(z);
return return
tensor tensor
( (
cos(y)*cos(z) - sin(x)*sin(y)*sin(z), cy*cz - sx*sy*sz, -cx*sz, sx*cy*sz + sy*cz,
-cos(x)*sin(z), cy*sz + sx*sy*cz, cx*cz, sy*sz - sx*cy*cz,
sin(x)*cos(y)*sin(z) + sin(y)*cos(z), -cx*sy, sx, cx*cy
cos(y)*sin(z) + sin(x)*sin(y)*cos(z),
cos(x)*cos(z),
sin(y)*sin(z) - sin(x)*cos(y)*cos(z),
-cos(x)*sin(y),
sin(x),
cos(x)*cos(y)
); );
} }