10 #ifndef INCLUDED_ATOMSMATHEULER_H
11 #define INCLUDED_ATOMSMATHEULER_H
13 #include <AtomsMath/ImathMath.h>
14 #include <AtomsMath/ImathMatrix.h>
15 #include <AtomsMath/ImathNamespace.h>
16 #include <AtomsMath/ImathQuat.h>
17 #include <AtomsMath/ImathVec.h>
21 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
23 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
25 # pragma warning(disable : 4244)
167 Legal = XYZ | XZY | YZX | YXZ | ZXY | ZYX | XZX | XYX | YXY | YZY | ZYZ | ZXZ | XYZr |
168 XZYr | YZXr | YXZr | ZXYr | ZYXr | XZXr | XYXr | YXYr | YZYr | ZYZr | ZXZr,
208 ATOMSMATH_HOSTDEVICE constexpr
Euler() noexcept;
211 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
Euler (const
Euler&) noexcept;
214 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
Euler (
Order p) noexcept;
217 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
Euler (const
Vec3<T>& v,
221 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
225 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
Euler (const
Euler<T>& euler,
Order newp) noexcept;
242 ATOMSMATH_HOSTDEVICE constexpr static
bool legal (
Order) noexcept;
245 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
Order order() const noexcept;
260 ATOMSMATH_HOSTDEVICE
void angleOrder (
int& i,
int& j,
int& k)
const noexcept;
263 ATOMSMATH_HOSTDEVICE
void angleMapping (
int& i,
int& j,
int& k)
const noexcept;
279 ATOMSMATH_HOSTDEVICE
void set (
Axis initial,
bool relative,
bool parityEven,
bool firstRepeats) noexcept;
326 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 static
float angleMod (T angle) noexcept;
333 ATOMSMATH_HOSTDEVICE static
void
355 #if defined _WIN32 || defined _WIN64
384 j = _parityEven ? (i + 1) % 3 : (i > 0 ? i - 1 : 2);
385 k = _parityEven ? (i > 0 ? i - 1 : 2) : (i + 1) % 3;
395 m[(_initialAxis + 1) % 3] = _parityEven ? 1 : 2;
396 m[(_initialAxis + 2) % 3] = _parityEven ? 2 : 1;
407 angleMapping (i, j, k);
418 angleMapping (i, j, k);
419 return Vec3<T> ((*
this)[i], (*
this)[j], (*
this)[k]);
426 _initialRepeated (false),
435 _initialRepeated (
false),
479 setXYZVector (
Vec3<T> (xi, yi, zi));
506 extract (q.toMatrix33());
514 angleOrder (i, j, k);
516 if (_initialRepeated)
522 x = std::atan2 (M[j][i], M[k][i]);
531 r[i] = (_parityEven ? -x : x);
556 T sy = std::sqrt (N[j][i] * N[j][i] + N[k][i] * N[k][i]);
557 y = std::atan2 (sy, N[i][i]);
558 z = std::atan2 (N[j][k], N[j][j]);
566 x = std::atan2 (M[j][k], M[k][k]);
575 r[i] = (_parityEven ? -x : x);
600 T cy = std::sqrt (N[i][i] * N[i][i] + N[i][j] * N[i][j]);
601 y = std::atan2 (-N[i][k], cy);
602 z = std::atan2 (-N[j][i], N[j][j]);
621 angleOrder (i, j, k);
623 if (_initialRepeated)
629 x = std::atan2 (M[j][i], M[k][i]);
638 r[i] = (_parityEven ? -x : x);
648 T sy = std::sqrt (N[j][i] * N[j][i] + N[k][i] * N[k][i]);
649 y = std::atan2 (sy, N[i][i]);
650 z = std::atan2 (N[j][k], N[j][j]);
658 x = std::atan2 (M[j][k], M[k][k]);
667 r[i] = (_parityEven ? -x : x);
677 T cy = std::sqrt (N[i][i] * N[i][i] + N[i][j] * N[i][j]);
678 y = std::atan2 (-N[i][k], cy);
679 z = std::atan2 (-N[j][i], N[j][j]);
698 angleOrder (i, j, k);
710 T ci = std::cos (angles.x);
711 T cj = std::cos (angles.y);
712 T ch = std::cos (angles.z);
713 T si = std::sin (angles.x);
714 T sj = std::sin (angles.y);
715 T sh = std::sin (angles.z);
724 if (_initialRepeated)
730 M[j][j] = -cj * ss + cc;
731 M[k][j] = -cj * cs - sc;
733 M[j][k] = cj * sc + cs;
734 M[k][k] = cj * cc - ss;
739 M[j][i] = sj * sc - cs;
740 M[k][i] = sj * cc + ss;
742 M[j][j] = sj * ss + cc;
743 M[k][j] = sj * cs - sc;
757 angleOrder (i, j, k);
769 T ci = std::cos (angles.x);
770 T cj = std::cos (angles.y);
771 T ch = std::cos (angles.z);
772 T si = std::sin (angles.x);
773 T sj = std::sin (angles.y);
774 T sh = std::sin (angles.z);
783 if (_initialRepeated)
789 M[j][j] = -cj * ss + cc;
790 M[k][j] = -cj * cs - sc;
792 M[j][k] = cj * sc + cs;
793 M[k][k] = cj * cc - ss;
798 M[j][i] = sj * sc - cs;
799 M[k][i] = sj * cc + ss;
801 M[j][j] = sj * ss + cc;
802 M[k][j] = sj * cs - sc;
817 angleOrder (i, j, k);
825 angles.y = -angles.y;
827 T ti = angles.x * 0.5;
828 T tj = angles.y * 0.5;
829 T th = angles.z * 0.5;
830 T ci = std::cos (ti);
831 T cj = std::cos (tj);
832 T ch = std::cos (th);
833 T si = std::sin (ti);
834 T sj = std::sin (tj);
835 T sh = std::sin (th);
841 T parity = _parityEven ? 1.0 : -1.0;
846 if (_initialRepeated)
848 a[i] = cj * (cs + sc);
849 a[j] = sj * (cc + ss) * parity,
850 a[k] = sj * (cs - sc);
851 q.
r = cj * (cc - ss);
855 a[i] = cj * sc - sj * cs,
856 a[j] = (cj * ss + sj * cc) * parity,
857 a[k] = cj * cs - sj * sc;
858 q.
r = cj * cc + sj * ss;
867 constexpr
inline bool
870 return (order & ~Legal) ? false :
true;
877 int foo = (_initialAxis == Z ? 0x2000 : (_initialAxis == Y ? 0x1000 : 0));
881 if (_initialRepeated)
893 set (p & 0x2000 ? Z : (p & 0x1000 ? Y : X),
904 _frameStatic = !relative;
905 _parityEven = parityEven;
906 _initialRepeated = firstRepeats;
910 ATOMSMATH_CONSTEXPR14
inline const Euler<T>&
916 _initialAxis = euler._initialAxis;
917 _frameStatic = euler._frameStatic;
918 _parityEven = euler._parityEven;
919 _initialRepeated = euler._initialRepeated;
924 ATOMSMATH_CONSTEXPR14
inline const Euler<T>&
936 operator<< (std::ostream& o,
const Euler<T>& euler) noexcept
938 char a[3] = {
'X',
'Y',
'Z' };
940 const char* r = euler.frameStatic() ?
"" :
"r";
942 euler.angleOrder (i, j, k);
944 if (euler.initialRepeated())
947 return o <<
"(" << euler.x <<
", " << euler.y <<
", " << euler.z <<
", " << a[i] << a[j] << a[k]
952 ATOMSMATH_CONSTEXPR14
inline float
955 const T pi =
static_cast<T
> (M_PI);
956 angle = fmod (T (angle), T (2 * pi));
970 Vec3<T> d = xyzRot - targetXyzRot;
971 xyzRot[0] = targetXyzRot[0] + angleMod (d[0]);
972 xyzRot[1] = targetXyzRot[1] + angleMod (d[1]);
973 xyzRot[2] = targetXyzRot[2] + angleMod (d[2]);
982 e.angleOrder (i, j, k);
984 simpleXYZRotation (xyzRot, targetXyzRot);
987 otherXyzRot[i] = M_PI + xyzRot[i];
988 otherXyzRot[j] = M_PI - xyzRot[j];
989 otherXyzRot[k] = M_PI + xyzRot[k];
991 simpleXYZRotation (otherXyzRot, targetXyzRot);
993 Vec3<T> d = xyzRot - targetXyzRot;
994 Vec3<T> od = otherXyzRot - targetXyzRot;
996 T odMag = od.
dot (od);
1000 xyzRot = otherXyzRot;
1008 Vec3<T> xyzRot = toXYZVector();
1010 if (order() != target.order())
1017 targetXyz = target.toXYZVector();
1020 nearestRotation (xyzRot, targetXyz, order());
1022 setXYZVector (xyzRot);
1025 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
1026 # pragma warning(default : 4244)
1031 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImathEuler.h:118
static ATOMSMATH_HOSTDEVICE void nearestRotation(Vec3< T > &xyzRot, const Vec3< T > &targetXyzRot, Order order=XYZ) noexcept
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 Order order() const noexcept
Return the order.
constexpr ATOMSMATH_HOSTDEVICE Euler() noexcept
No initialization by default.
constexpr ATOMSMATH_HOSTDEVICE bool frameStatic() const
Return frameStatic.
Definition: ImathEuler.h:248
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 const Euler< T > & operator=(const Euler< T > &) noexcept
Assignment.
Order
Definition: ImathEuler.h:129
InputLayout
Definition: ImathEuler.h:190
Axis _initialAxis
First axis of rotation.
Definition: ImathEuler.h:360
constexpr ATOMSMATH_HOSTDEVICE bool parityEven() const
Return partityEven.
Definition: ImathEuler.h:254
ATOMSMATH_HOSTDEVICE void set(Axis initial, bool relative, bool parityEven, bool firstRepeats) noexcept
Set the value.
ATOMSMATH_HOSTDEVICE void extract(const Quat< T > &) noexcept
Assign from Quaternion.
ATOMSMATH_HOSTDEVICE void setOrder(Order) noexcept
bool _parityEven
"parity of axis permutation"
Definition: ImathEuler.h:353
static ATOMSMATH_HOSTDEVICE void simpleXYZRotation(Vec3< T > &xyzRot, const Vec3< T > &targetXyzRot) noexcept
Adjust xyzRot so that its components differ from targetXyzRot by no more than +/-PI.
constexpr ATOMSMATH_HOSTDEVICE bool initialRepeated() const
Return intialRepeated.
Definition: ImathEuler.h:251
bool _frameStatic
relative or static rotations
Definition: ImathEuler.h:347
ATOMSMATH_HOSTDEVICE void angleOrder(int &i, int &j, int &k) const noexcept
Unpack angles from ijk form.
ATOMSMATH_HOSTDEVICE void makeNear(const Euler< T > &target) noexcept
ATOMSMATH_HOSTDEVICE Vec3< T > toXYZVector() const noexcept
Axis
Definition: ImathEuler.h:179
ATOMSMATH_HOSTDEVICE Quat< T > toQuat() const noexcept
Convert to Quat.
ATOMSMATH_HOSTDEVICE void angleMapping(int &i, int &j, int &k) const noexcept
Determine mapping from xyz to ijk (reshuffle the xyz to match the order)
ATOMSMATH_HOSTDEVICE Matrix44< T > toMatrix44() const noexcept
Convert to Matrix44.
ATOMSMATH_HOSTDEVICE static ATOMSMATH_CONSTEXPR14 float angleMod(T angle) noexcept
Convert an angle to its equivalent in [-PI, PI].
ATOMSMATH_HOSTDEVICE void extract(const Matrix44< T > &) noexcept
Assign from Matrix44, assumed to be affine.
ATOMSMATH_HOSTDEVICE void setXYZVector(const Vec3< T > &) noexcept
ATOMSMATH_HOSTDEVICE Matrix33< T > toMatrix33() const noexcept
Convert to Matrix33.
ATOMSMATH_HOSTDEVICE void extract(const Matrix33< T > &) noexcept
Assign from Matrix33, assumed to be affine.
bool _initialRepeated
init axis repeated as last
Definition: ImathEuler.h:350
constexpr ATOMSMATH_HOSTDEVICE Axis initialAxis() const
Return initialAxis.
Definition: ImathEuler.h:257
constexpr static ATOMSMATH_HOSTDEVICE bool legal(Order) noexcept
Return whether the given value is a legal Order.
Definition: ImathMatrix.h:305
Definition: ImathMatrix.h:631
ATOMSMATH_HOSTDEVICE const Matrix44 & rotate(const Vec3< S > &r) noexcept
Definition: ImathQuat.h:41
Vec3< T > v
The imaginary vector.
Definition: ImathQuat.h:51
T r
The real part.
Definition: ImathQuat.h:48
Definition: ImathVec.h:260
constexpr ATOMSMATH_HOSTDEVICE T dot(const Vec3 &v) const noexcept
Dot product.
Definition: ImathVec.h:1370