gemat3d.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. //
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright 2015 Autodesk, Inc. All rights reserved.
  6. //
  7. // Use of this software is subject to the terms of the Autodesk license
  8. // agreement provided at the time of installation or download, or which
  9. // otherwise accompanies this software in either electronic or hard copy form.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // DESCRIPTION:
  14. //
  15. // This file contains the class AcGeMatrix3d - a matrix used to
  16. // represent general purpose 3d transformations in homogeneous
  17. // co-ordinate space.
  18. #ifndef AC_GEMAT3D_H
  19. #define AC_GEMAT3D_H
  20. #include "gegbl.h"
  21. #include "gemat2d.h"
  22. #include "gepnt3d.h"
  23. #pragma pack (push, 8)
  24. class AcGeLine3d;
  25. class AcGeVector3d;
  26. class AcGePlane;
  27. class AcGeTol;
  28. class
  29. GE_DLLEXPIMPORT
  30. AcGeMatrix3d
  31. {
  32. public:
  33. AcGeMatrix3d();
  34. AcGeMatrix3d(const AcGeMatrix3d& src);
  35. // The multiplicative identity.
  36. //
  37. static const AcGeMatrix3d kIdentity;
  38. // Reset matrix.
  39. //
  40. AcGeMatrix3d& setToIdentity();
  41. // Multiplication.
  42. //
  43. AcGeMatrix3d operator * (const AcGeMatrix3d& mat) const;
  44. AcGeMatrix3d& operator *= (const AcGeMatrix3d& mat);
  45. AcGeMatrix3d& preMultBy (const AcGeMatrix3d& leftSide);
  46. AcGeMatrix3d& postMultBy (const AcGeMatrix3d& rightSide);
  47. AcGeMatrix3d& setToProduct (const AcGeMatrix3d& mat1, const AcGeMatrix3d& mat2);
  48. // Multiplicative inverse.
  49. //
  50. AcGeMatrix3d& invert ();
  51. AcGeMatrix3d inverse () const;
  52. AcGeMatrix3d inverse (const AcGeTol& tol) const;
  53. // Test if it is a singular matrix. A singular matrix is not invertable.
  54. //
  55. Adesk::Boolean isSingular (const AcGeTol& tol = AcGeContext::gTol) const;
  56. // Matrix transposition.
  57. //
  58. AcGeMatrix3d& transposeIt ();
  59. AcGeMatrix3d transpose () const;
  60. // Tests for equivalence using the infinity norm.
  61. //
  62. bool operator == (const AcGeMatrix3d& mat) const;
  63. bool operator != (const AcGeMatrix3d& mat) const;
  64. bool isEqualTo (const AcGeMatrix3d& mat, const AcGeTol& tol
  65. = AcGeContext::gTol) const;
  66. // Test scaling effects of matrix
  67. //
  68. Adesk::Boolean isUniScaledOrtho(const AcGeTol& tol = AcGeContext::gTol) const;
  69. Adesk::Boolean isScaledOrtho (const AcGeTol& tol = AcGeContext::gTol) const;
  70. // Determinant
  71. //
  72. double det () const;
  73. // Set/retrieve translation.
  74. //
  75. AcGeMatrix3d& setTranslation (const AcGeVector3d& vec);
  76. AcGeVector3d translation () const;
  77. // Set/get coordinate system
  78. //
  79. AcGeMatrix3d& setCoordSystem (const AcGePoint3d& origin,
  80. const AcGeVector3d& xAxis,
  81. const AcGeVector3d& yAxis,
  82. const AcGeVector3d& zAxis);
  83. void getCoordSystem (AcGePoint3d& origin,
  84. AcGeVector3d& xAxis,
  85. AcGeVector3d& yAxis,
  86. AcGeVector3d& zAxis) const;
  87. // Set the matrix to be a specified transformation
  88. //
  89. AcGeMatrix3d& setToTranslation(const AcGeVector3d& vec);
  90. AcGeMatrix3d& setToRotation (double angle, const AcGeVector3d& axis,
  91. const AcGePoint3d& center
  92. = AcGePoint3d::kOrigin);
  93. AcGeMatrix3d& setToScaling (double scaleAll, const AcGePoint3d& center
  94. = AcGePoint3d::kOrigin);
  95. AcGeMatrix3d& setToMirroring (const AcGePlane& pln);
  96. AcGeMatrix3d& setToMirroring (const AcGePoint3d& pnt);
  97. AcGeMatrix3d& setToMirroring (const AcGeLine3d& line);
  98. AcGeMatrix3d& setToProjection (const AcGePlane& projectionPlane,
  99. const AcGeVector3d& projectDir);
  100. AcGeMatrix3d& setToAlignCoordSys(const AcGePoint3d& fromOrigin,
  101. const AcGeVector3d& fromXAxis,
  102. const AcGeVector3d& fromYAxis,
  103. const AcGeVector3d& fromZAxis,
  104. const AcGePoint3d& toOrigin,
  105. const AcGeVector3d& toXAxis,
  106. const AcGeVector3d& toYAxis,
  107. const AcGeVector3d& toZAxis);
  108. AcGeMatrix3d& setToWorldToPlane(const AcGeVector3d& normal);
  109. AcGeMatrix3d& setToWorldToPlane(const AcGePlane& plane);
  110. AcGeMatrix3d& setToPlaneToWorld(const AcGeVector3d& normal);
  111. AcGeMatrix3d& setToPlaneToWorld(const AcGePlane& plane);
  112. // Similar to above, but creates matrix on the stack.
  113. //
  114. static
  115. AcGeMatrix3d translation (const AcGeVector3d& vec);
  116. static
  117. AcGeMatrix3d rotation (double angle, const AcGeVector3d& axis,
  118. const AcGePoint3d& center
  119. = AcGePoint3d::kOrigin);
  120. static
  121. AcGeMatrix3d scaling (double scaleAll, const AcGePoint3d& center
  122. = AcGePoint3d::kOrigin);
  123. static
  124. AcGeMatrix3d mirroring (const AcGePlane& pln);
  125. static
  126. AcGeMatrix3d mirroring (const AcGePoint3d& pnt);
  127. static
  128. AcGeMatrix3d mirroring (const AcGeLine3d& line);
  129. static
  130. AcGeMatrix3d projection (const AcGePlane& projectionPlane,
  131. const AcGeVector3d& projectDir);
  132. static
  133. AcGeMatrix3d alignCoordSys (const AcGePoint3d& fromOrigin,
  134. const AcGeVector3d& fromXAxis,
  135. const AcGeVector3d& fromYAxis,
  136. const AcGeVector3d& fromZAxis,
  137. const AcGePoint3d& toOrigin,
  138. const AcGeVector3d& toXAxis,
  139. const AcGeVector3d& toYAxis,
  140. const AcGeVector3d& toZAxis);
  141. static
  142. AcGeMatrix3d worldToPlane (const AcGeVector3d& normal);
  143. static
  144. AcGeMatrix3d worldToPlane (const AcGePlane&);
  145. static
  146. AcGeMatrix3d planeToWorld (const AcGeVector3d& normal);
  147. static
  148. AcGeMatrix3d planeToWorld (const AcGePlane&);
  149. // Get the length of the MAXIMUM column of the
  150. // 3x3 portion of the matrix.
  151. //
  152. double scale(void) const;
  153. double norm () const;
  154. AcGeMatrix2d convertToLocal (AcGeVector3d& normal, double& elev) const;
  155. // For convenient access to the data.
  156. //
  157. double operator () (unsigned int, unsigned int) const;
  158. double& operator () (unsigned int, unsigned int);
  159. // The components of the matrix.
  160. //
  161. double entry[4][4]; // [row][column]
  162. Adesk::Boolean inverse(AcGeMatrix3d& inv, double tol) const;
  163. private:
  164. void pivot (int, AcGeMatrix3d&);
  165. int pivotIndex(int) const;
  166. void swapRows (int, int, AcGeMatrix3d&);
  167. };
  168. inline bool
  169. AcGeMatrix3d::operator == (const AcGeMatrix3d& otherMatrix) const
  170. {
  171. return this->isEqualTo(otherMatrix);
  172. }
  173. // This operator is the logical negation of the `==' operator.
  174. //
  175. inline bool
  176. AcGeMatrix3d::operator != (const AcGeMatrix3d& otherMatrix) const
  177. {
  178. return !this->isEqualTo(otherMatrix);
  179. }
  180. // Return the element in position [row][column] of the `entry' array.
  181. //
  182. inline double
  183. AcGeMatrix3d::operator () (
  184. unsigned int row,
  185. unsigned int column) const
  186. {
  187. return entry[row][column];
  188. }
  189. inline double&
  190. AcGeMatrix3d::operator () (
  191. unsigned int row,
  192. unsigned int column)
  193. {
  194. return entry[row][column];
  195. }
  196. #pragma pack (pop)
  197. #endif