16#ifndef ROOT_MathX_GenVectorX_Transform3D
17#define ROOT_MathX_GenVectorX_Transform3D 1
78template <
typename T =
double>
132 template <
class ARotation,
class CoordSystem,
class Tag>
144 template <
class ARotation>
184 template <
class CoordSystem,
class Tag>
209 template <
class ARotation,
class CoordSystem,
class Tag>
231 template <typename SCALAR = T, typename std::enable_if<std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
237 Vector x1 = (fr1 - fr0).Unit();
238 Vector y1 = (fr2 - fr0).Unit();
239 Vector x2 = (to1 - to0).Unit();
240 Vector y2 = (to2 - to0).Unit();
244 const T cos1 = x1.
Dot(y1);
245 const T cos2 = x2.
Dot(y2);
247 if (std::fabs(T(1) - cos1) <= T(0.000001) || std::fabs(T(1) - cos2) <= T(0.000001)) {
248 std::cerr <<
"Transform3D: Error : zero angle between axes" << std::endl;
251 if (std::fabs(cos1 - cos2) > T(0.000001)) {
252 std::cerr <<
"Transform3D: Warning: angles between axes are not equal" << std::endl;
283 T detxx = (y1y * z1z - z1y * y1z);
284 T detxy = -(y1x * z1z - z1x * y1z);
285 T detxz = (y1x * z1y - z1x * y1y);
286 T detyx = -(x1y * z1z - z1y * x1z);
287 T detyy = (x1x * z1z - z1x * x1z);
288 T detyz = -(x1x * z1y - z1x * x1y);
289 T detzx = (x1y * y1z - y1y * x1z);
290 T detzy = -(x1x * y1z - y1x * x1z);
291 T detzz = (x1x * y1y - y1x * x1y);
293 T txx = x2x * detxx + y2x * detyx + z2x * detzx;
294 T txy = x2x * detxy + y2x * detyy + z2x * detzy;
295 T txz = x2x * detxz + y2x * detyz + z2x * detzz;
296 T tyx = x2y * detxx + y2y * detyx + z2y * detzx;
297 T tyy = x2y * detxy + y2y * detyy + z2y * detzy;
298 T tyz = x2y * detxz + y2y * detyz + z2y * detzz;
299 T tzx = x2z * detxx + y2z * detyx + z2z * detzx;
300 T tzy = x2z * detxy + y2z * detyy + z2z * detzy;
301 T tzz = x2z * detxz + y2z * detyz + z2z * detzz;
305 T dx1 = fr0.
x(), dy1 = fr0.
y(), dz1 = fr0.
z();
306 T dx2 = to0.
x(), dy2 = to0.
y(), dz2 = to0.
z();
308 SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz,
309 dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1);
325 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
331 Vector x1 = (fr1 - fr0).Unit();
332 Vector y1 = (fr2 - fr0).Unit();
333 Vector x2 = (to1 - to0).Unit();
334 Vector y2 = (to2 - to0).Unit();
338 const T cos1 = x1.
Dot(y1);
339 const T cos2 = x2.
Dot(y2);
341 const auto m1 = (abs(T(1) - cos1) <= T(0.000001) || abs(T(1) - cos2) <= T(0.000001));
343 const auto m2 = (abs(cos1 - cos2) > T(0.000001));
345 std::cerr <<
"Transform3D: Warning: angles between axes are not equal" << std::endl;
376 T detxx = (y1y * z1z - z1y * y1z);
377 T detxy = -(y1x * z1z - z1x * y1z);
378 T detxz = (y1x * z1y - z1x * y1y);
379 T detyx = -(x1y * z1z - z1y * x1z);
380 T detyy = (x1x * z1z - z1x * x1z);
381 T detyz = -(x1x * z1y - z1x * x1y);
382 T detzx = (x1y * y1z - y1y * x1z);
383 T detzy = -(x1x * y1z - y1x * x1z);
384 T detzz = (x1x * y1y - y1x * x1y);
386 T txx = x2x * detxx + y2x * detyx + z2x * detzx;
387 T txy = x2x * detxy + y2x * detyy + z2x * detzy;
388 T txz = x2x * detxz + y2x * detyz + z2x * detzz;
389 T tyx = x2y * detxx + y2y * detyx + z2y * detzx;
390 T tyy = x2y * detxy + y2y * detyy + z2y * detzy;
391 T tyz = x2y * detxz + y2y * detyz + z2y * detzz;
392 T tzx = x2z * detxx + y2z * detyx + z2z * detzx;
393 T tzy = x2z * detxy + y2z * detyy + z2z * detzy;
394 T tzz = x2z * detxz + y2z * detyz + z2z * detzz;
398 T dx1 = fr0.
x(), dy1 = fr0.
y(), dz1 = fr0.
z();
399 T dx2 = to0.
x(), dy2 = to0.
y(), dz2 = to0.
z();
401 SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz,
402 dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1);
405 std::cerr <<
"Transform3D: Error : zero angle between axes" << std::endl;
418 template <
class ForeignMatrix>
427 Transform3D(T xx, T xy, T xz, T dx, T yx, T yy, T yz, T dy, T zx, T zy, T zz, T dz)
429 SetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
438 template <
class ForeignMatrix>
454 for (
int i = 0; i < 12; ++i) {
459 assert(end == begin);
469 for (
int i = 0; i < 12; ++i) {
474 assert(end == begin);
483 std::copy(
fM,
fM + 12, begin);
492 template <
class ForeignMatrix>
514 template <
class ForeignMatrix>
534 void SetComponents(T xx, T xy, T xz, T dx, T yx, T yy, T yz, T dy, T zx, T zy, T zz, T dz)
553 void GetComponents(T &xx, T &xy, T &xz, T &dx, T &yx, T &yy, T &yz, T &dy, T &zx, T &zy, T &zz, T &dz)
const
573 template <
class AnyRotation,
class V>
600 template <
class AnyRotation>
609 template <
class AnyRotation>
624 template <
class AnyVector>
657 template <
class CoordSystem>
665 template <
class CoordSystem>
674 template <
class CoordSystem>
682 template <
class CoordSystem>
719 template <
class CoordSystem>
730 template <
class CoordSystem>
739 template <
class CoordSystem,
class Tag1,
class Tag2>
743 p2.
SetXYZ(xyzNew.
X(), xyzNew.
Y(), xyzNew.
Z());
749 template <
class CoordSystem,
class Tag1,
class Tag2>
753 v2.SetXYZ(xyzNew.
X(), xyzNew.
Y(), xyzNew.
Z());
759 template <
class CoordSystem>
768 template <
class CoordSystem>
777 template <
typename TYPE>
790 template <
typename TYPE>
811 template <typename SCALAR = T, typename std::enable_if<std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
825 std::cerr <<
"Transform3D::inverse error: zero determinant" << std::endl;
839 detxy *
fM[
kDX] - detyy *
fM[
kDY] + detzy *
fM[
kDZ], detxz, -detyz, detzz,
846 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
859 const auto detZmask = (det == T(0));
860 if (any_of(detZmask)) {
861 std::cerr <<
"Transform3D::inverse error: zero determinant" << std::endl;
862 where(detZmask, det) = T(1);
875 if (any_of(detZmask)) {
876 where(detZmask, detxx) = T(0);
877 where(detZmask, detxy) = T(0);
878 where(detZmask, detxz) = T(0);
879 where(detZmask, detyx) = T(0);
880 where(detZmask, detyy) = T(0);
881 where(detZmask, detyz) = T(0);
882 where(detZmask, detzx) = T(0);
883 where(detZmask, detzy) = T(0);
884 where(detZmask, detzz) = T(0);
888 detxy *
fM[
kDX] - detyy *
fM[
kDY] + detzy *
fM[
kDZ], detxz, -detyz, detzz,
908 return (
fM[0] == rhs.
fM[0] &&
fM[1] == rhs.
fM[1] &&
fM[2] == rhs.
fM[2] &&
fM[3] == rhs.
fM[3] &&
909 fM[4] == rhs.
fM[4] &&
fM[5] == rhs.
fM[5] &&
fM[6] == rhs.
fM[6] &&
fM[7] == rhs.
fM[7] &&
910 fM[8] == rhs.
fM[8] &&
fM[9] == rhs.
fM[9] &&
fM[10] == rhs.
fM[10] &&
fM[11] == rhs.
fM[11]);
928 r.GetComponents(rotData, rotData + 9);
930 for (
int i = 0; i < 3; ++i)
933 for (
int i = 0; i < 3; ++i)
934 fM[
kYX + i] = rotData[3 + i];
936 for (
int i = 0; i < 3; ++i)
937 fM[
kZX + i] = rotData[6 + i];
941 v.GetCoordinates(vecData, vecData + 3);
942 fM[
kDX] = vecData[0];
943 fM[
kDY] = vecData[1];
944 fM[
kDZ] = vecData[2];
954 r.GetComponents(rotData, rotData + 9);
955 for (
int i = 0; i < 3; ++i) {
956 for (
int j = 0; j < 3; ++j)
957 fM[4 * i + j] = rotData[3 * i + j];
959 fM[4 * i + 3] = T(0);
1007 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
1314 os <<
"\n" <<
m[0] <<
" " <<
m[1] <<
" " <<
m[2] <<
" " <<
m[3];
1315 os <<
"\n" <<
m[4] <<
" " <<
m[5] <<
" " <<
m[6] <<
" " <<
m[7];
1316 os <<
"\n" <<
m[8] <<
" " <<
m[9] <<
" " <<
m[10] <<
" " <<
m[11] <<
"\n";
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
DisplacementVector3D Cross(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return vector (cross) product of two displacement vectors, as a vector in the coordinate system of th...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
EulerAngles class describing rotation as three angles (Euler Angles).
Class describing a geometrical plane in 3 dimensions.
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Class describing a 3 dimensional translation.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Class describing a generic position vector (point) in 3 dimensions.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
PositionVector3D< CoordSystem, Tag > & SetXYZ(Scalar a, Scalar b, Scalar c)
set the values of the vector from the cartesian components (x,y,z) (if the vector is held in polar or...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Transform3D< T > operator*(const Rotation3D &r, const Translation3D< T > &t)
combine a translation and a rotation to give a transform3d First the translation then the rotation
std::ostream & operator<<(std::ostream &os, const Plane3D< T > &p)
Stream Output and Input.
Impl::Plane3D< double > Plane3D
Impl::Translation3D< double > Translation3D
Impl::Transform3D< float > Transform3DF
Impl::Transform3D< double > Transform3D