42 #ifndef EGS_TRANSFORMATIONS_
44 #define EGS_TRANSFORMATIONS_
59 inline void addTransformationBlock(shared_ptr<EGS_BlockInput> blockPtr) {
60 shared_ptr<EGS_BlockInput> transBlock = blockPtr->addBlockInput(
"transformation");
61 transBlock->addSingleInput(
"translation",
false,
"The x, y, z translation offsets in cm.");
62 auto vecPtr = transBlock->addSingleInput(
"rotation vector",
false,
"Defines a rotation which, when applied to the 3D vector defined by this input, transforms it into a vector along the positive z-axis.");
63 auto rotPtr = transBlock->addSingleInput(
"rotation",
false,
"2, 3 or 9 floating point numbers define a rotation. See the documentation for details.");
64 vecPtr->addDependency(rotPtr,
"",
true);
65 rotPtr->addDependency(vecPtr,
"",
true);
84 EGS_Float
rxx, rxy, rxz,
109 EGS_Float yx, EGS_Float yy, EGS_Float yz,
110 EGS_Float zx, EGS_Float zy, EGS_Float zz) {
143 EGS_Float d = det() - 1;
164 EGS_Float sinz = v.
x*v.
x + v.
y*v.
y;
165 EGS_Float norm = sinz + v.
z*v.
z;
166 if (norm <
epsilon)
egsFatal(
"EGS_RotationMatrix::EGS_RotationMatrix: \n"
167 " no construction from a zero vector possible!\n");
171 EGS_Float cphi = v.
x/sinz;
172 EGS_Float sphi = v.
y/sinz;
173 EGS_Float cost = v.
z/norm;
174 EGS_Float sint = -sinz/norm;
175 *
this = rotY(cost,sint)*rotZ(cphi,sphi);
200 *
this = rotX(alpha)*rotY(beta)*rotZ(gamma);
208 *
this = rotZ(phi)*rotX(theta);
228 ((rxx == m.
rxx) && (rxy == m.rxy) && (rxz == m.rxz) &&
229 (ryx == m.ryx) && (ryy == m.ryy) && (ryz == m.ryz) &&
230 (rzx == m.rxz) && (rzy == m.rzy) && (rzz == m.rzz)) ? true :
false;
255 ryx*v.
x + ryy*v.
y + ryz*v.
z,
256 rzx*v.
x + rzy*v.
y + rzz*v.
z);
263 rxx*m.
rxx+rxy*m.ryx+rxz*m.rzx, rxx*m.rxy+rxy*m.ryy+rxz*m.rzy,
264 rxx*m.rxz+rxy*m.ryz+rxz*m.rzz,
265 ryx*m.
rxx+ryy*m.ryx+ryz*m.rzx, ryx*m.rxy+ryy*m.ryy+ryz*m.rzy,
266 ryx*m.rxz+ryy*m.ryz+ryz*m.rzz,
267 rzx*m.
rxx+rzy*m.ryx+rzz*m.rzx, rzx*m.rxy+rzy*m.ryy+rzz*m.rzy,
268 rzx*m.rxz+rzy*m.ryz+rzz*m.rzz);
276 return *
this = operator * (m);
288 *
this = m.operator * (*this);
307 return *
this = inverse();
315 (EGS_Float)1,(EGS_Float)0,(EGS_Float)0,
316 (EGS_Float)0, cphi, sphi,
317 (EGS_Float)0, -sphi, cphi);
325 (EGS_Float)0, (EGS_Float)1, (EGS_Float)0,
326 sphi, (EGS_Float)0, cphi);
334 -sphi, cphi, (EGS_Float)0,
335 (EGS_Float)0,(EGS_Float)0, (EGS_Float)1);
340 return rotX(cos(phi),sin(phi));
345 return rotY(cos(phi),sin(phi));
350 return rotZ(cos(phi),sin(phi));
357 return rotV(cos(phi),sin(phi),v);
364 return (m.
inverse())*(rotZ(cphi,sphi))*(m);
369 return rxx*ryy*rzz + rxy*ryz*rzx + ryx*rzy*rxz -
370 rxz*ryy*rzx - rxy*ryx*rzz - rzy*ryz*rxx;
379 v.
x*m.rxy+v.
y*m.ryy+v.
z*m.rzy,
380 v.
x*m.rxz+v.
y*m.ryz+v.
z*m.rzz);
392 inline EGS_Float xx()
const {
395 inline EGS_Float xy()
const {
398 inline EGS_Float xz()
const {
401 inline EGS_Float yx()
const {
404 inline EGS_Float yy()
const {
407 inline EGS_Float yz()
const {
410 inline EGS_Float zx()
const {
413 inline EGS_Float zy()
const {
416 inline EGS_Float zz()
const {
447 R(tr.R),t(tr.t),has_t(tr.has_t),has_R(tr.has_R) {};
453 if (t.length2() > 0) {
483 if (t.length2() > 0) {
493 if (
this != &other) {
497 this->has_t = other.has_t;
498 this->has_R = other.has_R;
529 return *
this = operator * (tr);
538 return *
this = operator * (m);
561 return ((v-tr.t)*tr.R);
631 return (!has_R && !has_t);
685 static EGS_AffineTransform *getTransformation(vector<EGS_Float> trnsl, vector<EGS_Float> rot);
A class for vector rotations.
static EGS_RotationMatrix rotV(EGS_Float cphi, EGS_Float sphi, const EGS_Vector &v)
static EGS_RotationMatrix rotZ(EGS_Float phi)
Returns a rotation around the z-axis by the angle phi.
EGS_RotationMatrix(EGS_Float phi, EGS_Float theta)
Constructs a rotation matrix from the angles theta and phi (polar and azimuthal) as .
EGS_RotationMatrix()
Default constructor, results in a unit matrix object.
EGS_RotationMatrix operator*(const EGS_RotationMatrix &m) const
Multiplies the invoking object with m from the right and returns the result.
EGS_RotationMatrix(EGS_Float alpha, EGS_Float beta, EGS_Float gamma)
Constructs a rotation matrix from rotation angles around the x-, y-, and z-axis as .
bool isRotation() const
Is this object a real rotation matrix?
static EGS_RotationMatrix rotY(EGS_Float cphi, EGS_Float sphi)
Returns a rotation around the y-axis by the angle with cphi, sphi = .
EGS_RotationMatrix T()
Returns the transposed matrix.
EGS_RotationMatrix(const EGS_Vector &v)
Create a rotation matrix from the vector v.
EGS_Vector operator*(const EGS_Vector &v) const
Returns the rotated a vector .
static EGS_RotationMatrix rotV(EGS_Float phi, const EGS_Vector &v)
Returns a rotation by the angle phi around the axis defined by the vector v.
EGS_RotationMatrix & operator*=(const EGS_RotationMatrix &m)
Multiplies the invoking object with m from the right and assigns the resulting matrix to the invoking...
friend EGS_Vector operator*(const EGS_Vector &v, const EGS_RotationMatrix &m)
Multiplies the invoking vector v from the right with the matrix m and returns the result.
EGS_Float det() const
Calculates and returns the determinant of the matrix.
static EGS_RotationMatrix rotX(EGS_Float cphi, EGS_Float sphi)
Returns a rotation around the x-axis by the angle with cphi, sphi = .
EGS_RotationMatrix & operator=(const EGS_RotationMatrix &m)
Assignment operator.
EGS_RotationMatrix(const EGS_RotationMatrix &m)
Copy constructor.
static EGS_RotationMatrix rotY(EGS_Float phi)
Returns a rotation around the y-axis by the angle phi.
friend EGS_Vector & operator*=(EGS_Vector &v, const EGS_RotationMatrix &m)
Multiplies the invoking vector v from the right with the matrix m and assigns the result to the invok...
EGS_RotationMatrix & invert()
Inverts the matrix and returns a reference to it.
static EGS_RotationMatrix rotZ(EGS_Float cphi, EGS_Float sphi)
Returns a rotation around the z-axis by the angle with cphi, sphi = .
bool operator==(const EGS_RotationMatrix &m)
Comparison operator.
EGS_RotationMatrix(EGS_Float xx, EGS_Float xy, EGS_Float xz, EGS_Float yx, EGS_Float yy, EGS_Float yz, EGS_Float zx, EGS_Float zy, EGS_Float zz)
Construct a rotation matrix object from 9 floating point numbers.
void multiply(const EGS_RotationMatrix &m)
Multiplies the invoking object with m from the left and returns the result.
bool isI() const
Returns true, if this object is approximately the unit matrix, false otherwise.
EGS_RotationMatrix inverse() const
Returns the inverse matrix.
static EGS_RotationMatrix rotX(EGS_Float phi)
Returns a rotation around the x-axis by the angle phi.
A class representing 3D vectors.
Global egspp functions header file.
Defines the EGS_EXPORT and EGS_LOCAL macros.
#define EGS_EXPORT
Export symbols from the egspp library.
Attempts to fix broken math header files.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.