FEDEM Solver  R8.0
Source code of the dynamics solver
FFaMat34.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_MAT34_H
14 #define FFA_MAT34_H
15 
18 
19 
31 class FaMat34
32 {
33 public:
35  FaMat34() {}
37  FaMat34(const float* mat) : r(mat), p(mat+9) {}
39  FaMat34(const double* mat) : r(mat), p(mat+9) {}
41  explicit FaMat34(const FaVec3& pos) : p(pos) {}
43  FaMat34(const FaVec3& v0, const FaVec3& v1,
44  const FaVec3& v2, const FaVec3& v3) : r(v0,v1,v2), p(v3) {}
46  FaMat34(const FaMat33& m, const FaVec3& v) : r(m), p(v) {}
47 
49  FaMat34& operator+= (const FaMat34& m);
51  FaMat34& operator+= (const FaVec3& v);
53  FaMat34& operator-= (const FaMat34& m);
55  FaMat34& operator-= (const FaVec3& v);
57  FaMat34& operator*= (double d);
59  FaMat34& operator/= (double d);
60 
62  const FaVec3& operator[] (int i) const;
64  FaVec3& operator[] (int i);
65 
67  const double& operator() (int i, int j) const;
69  double& operator() (int i, int j);
70 
71  // Special functions
72 
74  const FaMat33& direction() const { return r; }
76  const FaVec3& translation() const { return p; }
77 
79  FaMat34 inverse() const;
82 
85  bool isCoincident(const FaMat34& m, double tolerance = 1.0e-10) const;
86 
88  FaMat34& eulerRotateZYX(const FaVec3& anglesXYZ, const FaMat34& fromMatrix);
90  FaMat34& eulerRotateZYX(const FaVec3& anglesXYZ);
92  FaMat34& eulerTransform(const FaVec3& offsetXYZ, const FaVec3& anglesXYZ,
93  const FaMat34& fromMatrix);
95  FaMat34& quatrTransform(const FaVec3& offsetXYZ, const FaVec3& anglesXYZ,
96  const FaMat34& fromMatrix);
97 
99  FaMat34& makeGlobalizedCS(const FaVec3& origin,
100  const FaVec3& p1);
102  FaMat34& makeGlobalizedCS(const FaVec3& origin,
103  const FaVec3& p1, const FaVec3& p2);
105  FaMat34& makeGlobalizedCS(const FaVec3& origin,
106  const FaVec3& p1, const FaVec3& p2,
107  const FaVec3& p3);
108 
110  FaMat34& makeCS_X_XY(const FaVec3& origin,
111  const FaVec3& xpt, const FaVec3& xypl);
113  FaMat34& makeCS_X_XZ(const FaVec3& origin,
114  const FaVec3& xpt, const FaVec3& xzpl);
116  FaMat34& makeCS_Z_XZ(const FaVec3& origin,
117  const FaVec3& zpt, const FaVec3& xzpl);
118 
120  FaVec3 projectOnXY(const FaVec3& x) const;
121 
123  FaVec3 getEulerZYX() const;
125  FaVec3 getEulerZYX(const FaMat34& from) const;
127  double getEulerZYX(int i) const;
129  double getEulerZYX(int i, const FaMat34& from) const;
131  double getRotation(int i) const;
133  double getRotation(int i, const FaMat34& from) const;
134 
135  // Reading and writing
136 
138  std::ostream& printStd(std::ostream& os) const;
140  std::ostream& printRot(std::ostream& os) const;
141 
143  bool readStd(std::istream& s);
145  bool readRot(std::istream& s);
146 
147  // Global operators
148 
150  friend FaMat34 operator- (const FaMat34& a);
152  friend FaMat34 operator+ (const FaMat34& a, const FaMat34& b);
154  friend FaMat34 operator+ (const FaMat34& a, const FaVec3& b);
156  friend FaMat34 operator- (const FaMat34& a, const FaMat34& b);
158  friend FaMat34 operator- (const FaMat34& a, const FaVec3& b);
159 
161  friend FaMat34 operator* (const FaMat34& a, const FaMat34& b);
163  friend FaMat34 operator* (const FaMat34& a, const FaMat33& b);
165  friend FaVec3 operator* (const FaMat34& a, const FaVec3& b);
166 
168  friend bool operator== (const FaMat34& a, const FaMat34& b);
170  friend bool operator!= (const FaMat34& a, const FaMat34& b);
171 
173  friend std::ostream& operator<< (std::ostream& s, const FaMat34& m);
175  friend std::istream& operator>> (std::istream& s, FaMat34& m);
176 
177 private:
180 };
181 
182 
183 // --- inline functions ---
184 
185 inline const FaVec3& FaMat34::operator[] (int i) const
186 {
187 #ifdef FFA_INDEXCHECK
188  if (i < 0 || i > 3)
189  std::cerr <<"FaMat34::operator[]: index i="<< i <<" is out of range [0,3]"
190  << std::endl;
191 #endif
192  return i == 3 ? p : r[i];
193 }
194 
196 {
197 #ifdef FFA_INDEXCHECK
198  if (i < 0 || i > 3)
199  std::cerr <<"FaMat34::operator[]: index i="<< i <<" is out of range [0,3]"
200  << std::endl;
201 #endif
202  return i == 3 ? p : r[i];
203 }
204 
205 // Fortran-like 1-based indexing operators.
206 // The first index is the row number, whereas the second is the column number.
207 
208 inline const double& FaMat34::operator() (int i, int j) const
209 {
210  return j == 4 ? p[i-1] : r[j-1][i-1];
211 }
212 
213 inline double& FaMat34::operator() (int i, int j)
214 {
215  return j == 4 ? p[i-1] : r[j-1][i-1];
216 }
217 
218 #endif
Point transformations in 3D space.
Point vectors in 3D space.
Class for point transformations in 3D space.
Definition: FFaMat33.H:27
Class for positions in 3D space.
Definition: FFaMat34.H:32
friend FaMat34 operator+(const FaMat34 &a, const FaMat34 &b)
Global addition operator.
FaMat34 & quatrTransform(const FaVec3 &offsetXYZ, const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Computes a relative rotation from given rotation angles and offset.
Definition: FFaMat34.C:134
FaMat34 & makeCS_X_XY(const FaVec3 &origin, const FaVec3 &xpt, const FaVec3 &xypl)
Computes a coordinate from points in the XY-plane and the X-axis.
Definition: FFaMat34.C:210
friend std::ostream & operator<<(std::ostream &s, const FaMat34 &m)
Printing operator.
friend bool operator!=(const FaMat34 &a, const FaMat34 &b)
Inequality operator.
FaMat34 & operator+=(const FaMat34 &m)
Addition operator.
Definition: FFaMat34.C:37
FaMat34()
Default constructor creating an identity matrix at the origin.
Definition: FFaMat34.H:35
FaMat34(const double *mat)
Constructor creating a matrix from a double array.
Definition: FFaMat34.H:39
FaMat34(const FaVec3 &v0, const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Constructor creating a identity matrix from four column vectors.
Definition: FFaMat34.H:43
friend FaMat34 operator-(const FaMat34 &a)
Unary negation operator.
FaMat34 & operator-=(const FaMat34 &m)
Subtraction operator.
Definition: FFaMat34.C:51
const FaMat33 & direction() const
Returns a const reference to the orientation matrix r.
Definition: FFaMat34.H:74
FaMat34 & makeCS_Z_XZ(const FaVec3 &origin, const FaVec3 &zpt, const FaVec3 &xzpl)
Computes a coordinate from points in the XZ-plane and the Z-axis.
Definition: FFaMat34.C:236
FaMat34 & makeGlobalizedCS(const FaVec3 &origin, const FaVec3 &p1)
Computes a globalized coordinate system from trwo vectors.
Definition: FFaMat34.C:144
double getRotation(int i) const
Returns the angles corresponding to the orientation r.
Definition: FFaMat34.C:199
FaMat34 & operator/=(double d)
Scaling operator (division by a scalar).
Definition: FFaMat34.C:73
friend FaMat34 operator*(const FaMat34 &a, const FaMat34 &b)
Multiplication of two matrices.
bool readStd(std::istream &s)
Reads the matrix from the provided input stream.
Definition: FFaMat34.C:304
FaMat34 & makeCS_X_XZ(const FaVec3 &origin, const FaVec3 &xpt, const FaVec3 &xzpl)
Computes a coordinate from points in the XZ-plane and the X-axis.
Definition: FFaMat34.C:223
FaMat34 & eulerTransform(const FaVec3 &offsetXYZ, const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Computes a relative rotation from given Euler angles and offset.
Definition: FFaMat34.C:124
friend std::istream & operator>>(std::istream &s, FaMat34 &m)
Reading operator.
FaMat34 & eulerRotateZYX(const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Computes a relative rotation from the given Euler angles.
Definition: FFaMat34.C:116
FaMat34(const FaVec3 &pos)
Constructor creating an identity matrix at the the point pos.
Definition: FFaMat34.H:41
FaMat33 r
Orientation matrix.
Definition: FFaMat34.H:178
const FaVec3 & operator[](int i) const
Zero-based indexing operator accessing a matrix column (read only).
Definition: FFaMat34.H:185
const FaVec3 & translation() const
Returns a const reference to the position vector p.
Definition: FFaMat34.H:76
FaMat34 inverse() const
Returns the inverse of the matrix.
Definition: FFaMat34.C:87
FaMat34 & setIdentity()
Initializes the matrix to the indentity rotation at the origin.
Definition: FFaMat34.C:93
FaVec3 p
Position vector.
Definition: FFaMat34.H:179
std::ostream & printRot(std::ostream &os) const
Writes the matrix to the provided output stream.
Definition: FFaMat34.C:289
FaVec3 projectOnXY(const FaVec3 &x) const
Calculates the projection of x onto the XY-plane of this matrix.
Definition: FFaMat34.C:170
FaVec3 getEulerZYX() const
Returns the Euler angles corresponding to the orientation r.
Definition: FFaMat34.C:177
friend bool operator==(const FaMat34 &a, const FaMat34 &b)
Equality operator.
FaMat34 & operator*=(double d)
Scaling operator (multiplication by a scalar).
Definition: FFaMat34.C:65
std::ostream & printStd(std::ostream &os) const
Writes the matrix to the provided output stream.
Definition: FFaMat34.C:264
const double & operator()(int i, int j) const
One-based indexing operator accessing a matrix element (read only).
Definition: FFaMat34.H:208
bool isCoincident(const FaMat34 &m, double tolerance=1.0e-10) const
Returns true if the matrix m equals *this within the given tolerance.
Definition: FFaMat34.C:101
FaMat34(const float *mat)
Constructor creating a matrix from a float array.
Definition: FFaMat34.H:37
FaMat34(const FaMat33 &m, const FaVec3 &v)
Constructor creating a matrix from given rotation and position.
Definition: FFaMat34.H:46
bool readRot(std::istream &s)
Reads the matrix from the provided input stream.
Definition: FFaMat34.C:323
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(sp), dimension(:,:,:), pointer b
Definition: diffractionModule.f90:22
real(sp), dimension(:,:,:), pointer a
Definition: diffractionModule.f90:21
real(dp), dimension(:,:), allocatable m
Definition: inverseModule.f90:38
real(dp), dimension(:), allocatable v0
Definition: inverseModule.f90:26
real(dp), dimension(:), allocatable v1
Definition: inverseModule.f90:27
real(dp), dimension(:), allocatable v2
Definition: inverseModule.f90:28