File: transform3d.h

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (132 lines) | stat: -rw-r--r-- 4,108 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***********************************************/
/**
* @file transform3d.h
*
* @brief Orthogonal coordinate transformations in 3d space.
* (rotations and reflections).
*
* @author Torsten Mayer-Guerr
* @date 2019-03-03
*
*/
/***********************************************/

#ifndef __GROOPS_TRANSFORM3D__
#define __GROOPS_TRANSFORM3D__

#include "base/importStd.h"
#include "base/matrix.h"

/** @addtogroup vector3dGroup */
/// @{

class Angle;
class Vector3d;
class Tensor3d;
class Rotary3d;
class Ellipsoid;

/***** CLASS ***********************************/

/** @brief Coordinate transformations in 3d space.
* (rotations and reflections). */
class Transform3d
{
  std::array<std::array<Double,3>,3> field;

public:
  Transform3d() : field{{{1.,0.,0.}, {0.,1.,0.}, {0.,0.,1.}}} {} //!< Default constructor (Unitary matrix).

  /// Contructor from std::array.
  Transform3d(const std::array<std::array<Double,3>,3> &x) : field(x) {}

  /// Contructor from Rotary3d.
  Transform3d(const Rotary3d &rot);

  /// Contructor from matrix (3x3).
  explicit Transform3d(const_MatrixSliceRef A);

  /** @brief Rotation of a local system.
  * Rotational matrix from local system (defined by the given axis x,y,z)
  * in the global system. The axis will be normalized and orthogonalized before.
  * The z-axis is defined orthogonal to x and y.
  * Zhe y-axis is defined orthogonal to the new z-axis and x. */
  Transform3d(Vector3d x, Vector3d y);

  /// Cast to Matrix.
  Matrix matrix() const;

  /** @brief Transformation of a vector.
  * \f[ y = T \cdot v \f]. */
  Vector3d transform(const Vector3d &v) const;

  /** @brief Inverse transformation of a vector.
  * \f[ y = T^T \cdot v \f]. */
  Vector3d inverseTransform(const Vector3d &v) const;

  /** @brief Transformation of  a tensor.
  * Both sides of the dyadic product are rotated.
  * \f[ y = T \cdot t \cdot T^T \f]. */
  Tensor3d transform(const Tensor3d &t) const;

  /** @brief Inverse transformation of a tensor.
  * Both sides of the dyadic product are rotated.
  * \f[ y = T^T \cdot t \cdot T \f]. */
  Tensor3d inverseTransform(const Tensor3d &t) const;

  Transform3d &operator*=(const Transform3d &b);
  Transform3d &operator*=(const Rotary3d &b);
  Transform3d  operator* (const Transform3d &b) const;
  Transform3d  operator* (const Rotary3d &b) const;

  friend class Rotary3d;
  friend Transform3d inverse(const Transform3d &b);
  friend Transform3d localNorthEastUp(const Vector3d &point);
  friend Transform3d localNorthEastUp(const Vector3d &point, const Ellipsoid &ellipsoid);
};

/***********************************************/

/** @brief flip x-axis. */
inline Transform3d flipX() {return Transform3d(std::array<std::array<Double,3>,3>{{{-1.,0.,0.}, {0.,1.,0.}, {0.,0.,1.}}});}

/** @brief flip y-axis. */
inline Transform3d flipY() {return Transform3d(std::array<std::array<Double,3>,3>{{{1.,0.,0.}, {0.,-1.,0.}, {0.,0.,1.}}});}

/** @brief flip z-axis. */
inline Transform3d flipZ() {return Transform3d(std::array<std::array<Double,3>,3>{{{1.,0.,0.}, {0.,1.,0.}, {0.,0.,-1.}}});}

/** @brief Transform3d of inverse rotation.
* @ingroup vector3dGroup
* Transposed matrix. */
Transform3d inverse(const Transform3d &b);

/** @brief Rotational matrix from local system (north, east, up) to the global system (coordinate system of point).
* @ingroup vector3dGroup */
Transform3d localNorthEastUp(const Vector3d &point);

/** @brief Rotational matrix from local system (north, east, up) to the global system (coordinate system of point).
* @ingroup vector3dGroup
* Converts @p point to ellipsoidal coordinates beforehand. */
Transform3d localNorthEastUp(const Vector3d &point, const Ellipsoid &ellipsoid);

/// @}

/***********************************************/
/***** INLINES *********************************/
/***********************************************/

inline Matrix Transform3d::matrix() const
{
  Matrix R(3, 3, Matrix::NOFILL);
  for(UInt i=0; i<3; i++)
    for(UInt k=0; k<3; k++)
      R(i,k) = field[i][k];
  return R;
}

/*************************************************/

#endif /* __GROOPS_TRANSFORM3D__ */