16 #ifndef ROOT_Math_GenVector_Transform3D 17 #define ROOT_Math_GenVector_Transform3D 1 39 #include <type_traits> 77 template <
typename T =
double>
130 template <
class ARotation,
class CoordSystem,
class Tag>
142 template <
class ARotation>
199 template<
class CoordSystem,
class Tag>
226 template <
class ARotation,
class CoordSystem,
class Tag>
248 template <typename SCALAR = T, typename std::enable_if<std::is_arithmetic<SCALAR>::value>
::type * =
nullptr>
249 Transform3D(
const Point &fr0,
const Point &fr1,
const Point &fr2,
const Point &to0,
const Point &to1,
254 Vector
x1 = (fr1 - fr0).
Unit();
255 Vector y1 = (fr2 - fr0).
Unit();
256 Vector
x2 = (to1 - to0).
Unit();
257 Vector y2 = (to2 - to0).
Unit();
261 const T cos1 = x1.
Dot(y1);
262 const T cos2 = x2.
Dot(y2);
265 std::cerr <<
"Transform3D: Error : zero angle between axes" << std::endl;
269 std::cerr <<
"Transform3D: Warning: angles between axes are not equal" << std::endl;
300 T detxx = (y1y * z1z - z1y * y1z);
301 T detxy = -(y1x * z1z - z1x * y1z);
302 T detxz = (y1x * z1y - z1x * y1y);
303 T detyx = -(x1y * z1z - z1y * x1z);
304 T detyy = (x1x * z1z - z1x * x1z);
305 T detyz = -(x1x * z1y - z1x * x1y);
306 T detzx = (x1y * y1z - y1y * x1z);
307 T detzy = -(x1x * y1z - y1x * x1z);
308 T detzz = (x1x * y1y - y1x * x1y);
310 T txx = x2x * detxx + y2x * detyx + z2x * detzx;
311 T txy = x2x * detxy + y2x * detyy + z2x * detzy;
312 T txz = x2x * detxz + y2x * detyz + z2x * detzz;
313 T tyx = x2y * detxx + y2y * detyx + z2y * detzx;
314 T tyy = x2y * detxy + y2y * detyy + z2y * detzy;
315 T tyz = x2y * detxz + y2y * detyz + z2y * detzz;
316 T tzx = x2z * detxx + y2z * detyx + z2z * detzx;
317 T tzy = x2z * detxy + y2z * detyy + z2z * detzy;
318 T tzz = x2z * detxz + y2z * detyz + z2z * detzz;
322 T dx1 = fr0.
x(), dy1 = fr0.
y(), dz1 = fr0.
z();
323 T dx2 = to0.
x(), dy2 = to0.
y(), dz2 = to0.
z();
325 SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz,
326 dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1);
342 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>::type * =
nullptr>
343 Transform3D(
const Point &fr0,
const Point &fr1,
const Point &fr2,
const Point &to0,
const Point &to1,
348 Vector
x1 = (fr1 - fr0).
Unit();
349 Vector y1 = (fr2 - fr0).
Unit();
350 Vector
x2 = (to1 - to0).
Unit();
351 Vector y2 = (to2 - to0).
Unit();
355 const T cos1 = x1.
Dot(y1);
356 const T cos2 = x2.
Dot(y2);
358 const auto m1 = (abs(
T(1) - cos1) <=
T(0.000001) || abs(
T(1) - cos2) <=
T(0.000001));
360 const auto m2 = (abs(cos1 - cos2) >
T(0.000001));
362 std::cerr <<
"Transform3D: Warning: angles between axes are not equal" << std::endl;
393 T detxx = (y1y * z1z - z1y * y1z);
394 T detxy = -(y1x * z1z - z1x * y1z);
395 T detxz = (y1x * z1y - z1x * y1y);
396 T detyx = -(x1y * z1z - z1y * x1z);
397 T detyy = (x1x * z1z - z1x * x1z);
398 T detyz = -(x1x * z1y - z1x * x1y);
399 T detzx = (x1y * y1z - y1y * x1z);
400 T detzy = -(x1x * y1z - y1x * x1z);
401 T detzz = (x1x * y1y - y1x * x1y);
403 T txx = x2x * detxx + y2x * detyx + z2x * detzx;
404 T txy = x2x * detxy + y2x * detyy + z2x * detzy;
405 T txz = x2x * detxz + y2x * detyz + z2x * detzz;
406 T tyx = x2y * detxx + y2y * detyx + z2y * detzx;
407 T tyy = x2y * detxy + y2y * detyy + z2y * detzy;
408 T tyz = x2y * detxz + y2y * detyz + z2y * detzz;
409 T tzx = x2z * detxx + y2z * detyx + z2z * detzx;
410 T tzy = x2z * detxy + y2z * detyy + z2z * detzy;
411 T tzz = x2z * detxz + y2z * detyz + z2z * detzz;
415 T dx1 = fr0.
x(), dy1 = fr0.
y(), dz1 = fr0.
z();
416 T dx2 = to0.
x(), dy2 = to0.
y(), dz2 = to0.
z();
418 SetComponents(txx, txy, txz, dx2 - txx * dx1 - txy * dy1 - txz * dz1, tyx, tyy, tyz,
419 dy2 - tyx * dx1 - tyy * dy1 - tyz * dz1, tzx, tzy, tzz, dz2 - tzx * dx1 - tzy * dy1 - tzz * dz1);
422 std::cerr <<
"Transform3D: Error : zero angle between axes" << std::endl;
435 template<
class ForeignMatrix>
443 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)
445 SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
455 template <
class ForeignMatrix>
476 for (
int i = 0; i <12; ++i) {
493 for (
int i = 0; i <12; ++i) {
505 std::copy(
fM,
fM + 12, begin);
514 template<
class ForeignMatrix>
527 template<
class ForeignMatrix>
539 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)
549 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 561 template<
class AnyRotation,
class V>
588 template <
class AnyRotation>
596 template <
class AnyRotation>
610 template <
class AnyVector>
644 template <
class CoordSystem>
652 template <
class CoordSystem>
661 template<
class CoordSystem >
668 template <
class CoordSystem>
705 template <
class CoordSystem>
716 template <
class CoordSystem>
725 template <
class CoordSystem,
class Tag1,
class Tag2>
729 p2.
SetXYZ( xyzNew.
X(), xyzNew.
Y(), xyzNew.
Z() );
736 template <
class CoordSystem,
class Tag1,
class Tag2>
740 v2.
SetXYZ( xyzNew.
X(), xyzNew.
Y(), xyzNew.
Z() );
746 template <
class CoordSystem >
754 template <
class CoordSystem>
763 template <
typename TYPE>
771 Point p(-d *
n.X(), -d *
n.Y(), -d *
n.Z());
776 template <
typename TYPE>
797 template <typename SCALAR = T, typename std::enable_if<std::is_arithmetic<SCALAR>::value>::type * =
nullptr>
809 T det = fM[
kXX] * detxx - fM[
kXY] * detxy + fM[
kXZ] * detxz;
811 std::cerr <<
"Transform3D::inverse error: zero determinant" << std::endl;
824 SetComponents(detxx, -detyx, detzx, -detxx * fM[
kDX] + detyx * fM[
kDY] - detzx * fM[
kDZ], -detxy, detyy, -detzy,
825 detxy * fM[
kDX] - detyy * fM[
kDY] + detzy * fM[kDZ], detxz, -detyz, detzz,
826 -detxz * fM[
kDX] + detyz * fM[
kDY] - detzz * fM[kDZ]);
832 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>::type * =
nullptr>
844 T det = fM[
kXX] * detxx - fM[
kXY] * detxy + fM[
kXZ] * detxz;
845 const auto detZmask = (det ==
T(0));
846 if (any_of(detZmask)) {
847 std::cerr <<
"Transform3D::inverse error: zero determinant" << std::endl;
848 det(detZmask) =
T(1);
861 if (any_of(detZmask)) {
862 detxx(detZmask) =
T(0);
863 detxy(detZmask) =
T(0);
864 detxz(detZmask) =
T(0);
865 detyx(detZmask) =
T(0);
866 detyy(detZmask) =
T(0);
867 detyz(detZmask) =
T(0);
868 detzx(detZmask) =
T(0);
869 detzy(detZmask) =
T(0);
870 detzz(detZmask) =
T(0);
873 SetComponents(detxx, -detyx, detzx, -detxx * fM[
kDX] + detyx * fM[
kDY] - detzx * fM[
kDZ], -detxy, detyy, -detzy,
874 detxy * fM[
kDX] - detyy * fM[
kDY] + detzy * fM[kDZ], detxz, -detyz, detzz,
875 -detxz * fM[
kDX] + detyz * fM[
kDY] - detzz * fM[kDZ]);
894 return (
fM[0] == rhs.
fM[0] &&
fM[1] == rhs.
fM[1] &&
fM[2] == rhs.
fM[2] &&
fM[3] == rhs.
fM[3] &&
895 fM[4] == rhs.
fM[4] &&
fM[5] == rhs.
fM[5] &&
fM[6] == rhs.
fM[6] &&
fM[7] == rhs.
fM[7] &&
896 fM[8] == rhs.
fM[8] &&
fM[9] == rhs.
fM[9] &&
fM[10] == rhs.
fM[10] &&
fM[11] == rhs.
fM[11]);
917 for (
int i = 0; i < 3; ++i)
fM[i] = rotData[i];
919 for (
int i = 0; i < 3; ++i)
fM[
kYX + i] = rotData[3 + i];
921 for (
int i = 0; i < 3; ++i)
fM[
kZX + i] = rotData[6 + i];
926 fM[
kDX] = vecData[0];
927 fM[
kDY] = vecData[1];
928 fM[
kDZ] = vecData[2];
939 for (
int i = 0; i < 3; ++i) {
940 for (
int j = 0; j < 3; ++j)
fM[4 * i + j] = rotData[3 * i + j];
942 fM[4 * i + 3] =
T(0);
990 template <typename SCALAR = T, typename std::enable_if<!std::is_arithmetic<SCALAR>::value>::type * =
nullptr>
1302 std::ostream &operator<<(std::ostream &os, const Transform3D<T> &t)
1308 t.GetComponents(m, m + 12);
1309 os <<
"\n" << m[0] <<
" " << m[1] <<
" " << m[2] <<
" " << m[3];
1310 os <<
"\n" << m[4] <<
" " << m[5] <<
" " << m[6] <<
" " << m[7];
1311 os <<
"\n" << m[8] <<
" " << m[9] <<
" " << m[10] <<
" " << m[11] <<
"\n";
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Scalar HesseDistance() const
Return the Hesse Distance (distance from the origin) of the plane or the d coefficient expressed in n...
DisplacementVector3D< 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...
Namespace for new ROOT classes and functions.
void GetComponents(ForeignVector &v1, ForeignVector &v2, ForeignVector &v3) const
Get components into three vectors which will be the (orthonormal) columns of the rotation matrix...
Vector Normal() const
Return normal vector to the plane as Cartesian DisplacementVector.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Impl::Transform3D< float > Transform3DF
Class describing a generic position vector (point) in 3 dimensions.
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
static const double x2[5]
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
unsigned int r3[N_CITIES]
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
static double p2(double t, double a, double b, double c)
Scalar E() const
return 4-th component (time, or energy for a 4-momentum vector)
Class describing a 3 dimensional translation.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Class describing a generic displacement vector in 3 dimensions.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
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...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
static double p1(double t, double a, double b)
void GetCoordinates(Scalar &a, Scalar &b, Scalar &c) const
get internal data into 3 Scalar numbers
static const double x1[5]
EulerAngles class describing rotation as three angles (Euler Angles).
Namespace for new Math classes and functions.
Scalar Y() const
Cartesian Y, 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...
Class describing a geometrical plane in 3 dimensions.
SVector< T, D > Unit(const SVector< T, D > &rhs)
Unit.
DefaultCoordinateSystemTag Default tag for identifying any coordinate system.
::ROOT::Math::DisplacementVector3D< Cartesian3D< Scalar > > Vect() const
get the spatial components of the Vector in a DisplacementVector based on Cartesian Coordinates ...
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.