gepnt3d.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. // DESCRIPTION:
  12. //
  13. // This file contains the class AcGePoint3d - A mathematical entity
  14. // used to represent a location in 3-space using homogeneous
  15. // co-ordinates (implicitly).
  16. #ifndef AC_GEPNT3D_H
  17. #define AC_GEPNT3D_H
  18. #include "gevec3d.h"
  19. #pragma pack (push, 8)
  20. class AcGeMatrix3d;
  21. class AcGeLinearEnt3d;
  22. class AcGePlane;
  23. class AcGePlanarEnt;
  24. class AcGeVector3d;
  25. class AcGePoint2d;
  26. class
  27. GE_DLLEXPIMPORT
  28. AcGePoint3d
  29. {
  30. public:
  31. AcGePoint3d();
  32. AcGePoint3d(const AcGePoint3d& pnt);
  33. AcGePoint3d(double x, double y, double z);
  34. AcGePoint3d(const AcGePlanarEnt& pln, const AcGePoint2d& pnt2d);
  35. // The origin, or (0, 0, 0).
  36. //
  37. static const AcGePoint3d kOrigin;
  38. // Matrix multiplication.
  39. //
  40. friend
  41. GE_DLLEXPIMPORT
  42. AcGePoint3d operator * (const AcGeMatrix3d& mat, const AcGePoint3d& pnt);
  43. AcGePoint3d& setToProduct(const AcGeMatrix3d& mat, const AcGePoint3d& pnt);
  44. AcGePoint3d& transformBy (const AcGeMatrix3d& leftSide);
  45. AcGePoint3d& rotateBy (double angle, const AcGeVector3d& vec,
  46. const AcGePoint3d& wrtPoint = AcGePoint3d::kOrigin);
  47. AcGePoint3d& mirror (const AcGePlane& pln);
  48. AcGePoint3d& scaleBy (double scaleFactor, const AcGePoint3d&
  49. wrtPoint = AcGePoint3d::kOrigin);
  50. AcGePoint2d convert2d (const AcGePlanarEnt& pln) const;
  51. // Scale multiplication.
  52. //
  53. AcGePoint3d operator * (double scl) const;
  54. friend
  55. AcGePoint3d operator * (double scl, const AcGePoint3d& pnt);
  56. AcGePoint3d& operator *= (double scl);
  57. AcGePoint3d operator / (double scl) const;
  58. AcGePoint3d& operator /= (double scl);
  59. // Translation by a vector.
  60. //
  61. AcGePoint3d operator + (const AcGeVector3d& vec) const;
  62. AcGePoint3d& operator += (const AcGeVector3d& vec);
  63. AcGePoint3d operator - (const AcGeVector3d& vec) const;
  64. AcGePoint3d& operator -= (const AcGeVector3d& vec);
  65. AcGePoint3d& setToSum (const AcGePoint3d& pnt, const AcGeVector3d& vec);
  66. // Get the vector between two points.
  67. //
  68. AcGeVector3d operator - (const AcGePoint3d& pnt) const;
  69. AcGeVector3d asVector () const;
  70. // Distance to other geometric objects.
  71. //
  72. double distanceTo (const AcGePoint3d& pnt) const;
  73. // Projection on plane
  74. //
  75. AcGePoint3d project (const AcGePlane& pln, const AcGeVector3d& vec) const;
  76. AcGePoint3d orthoProject (const AcGePlane& pln) const;
  77. // Tests for equivalence using the Euclidean norm.
  78. //
  79. bool operator == (const AcGePoint3d& pnt) const;
  80. bool operator != (const AcGePoint3d& pnt) const;
  81. bool isEqualTo (const AcGePoint3d& pnt,
  82. const AcGeTol& tol = AcGeContext::gTol) const;
  83. // For convenient access to the data.
  84. //
  85. double operator [] (unsigned int i) const;
  86. double& operator [] (unsigned int idx);
  87. AcGePoint3d& set (double x, double y, double z);
  88. AcGePoint3d& set (const AcGePlanarEnt& pln, const AcGePoint2d& pnt);
  89. // The co-ordinates of the point.
  90. //
  91. double x, y, z;
  92. };
  93. // Creates a point at the origin.
  94. //
  95. inline
  96. AcGePoint3d::AcGePoint3d() : x(0.0), y(0.0), z(0.0)
  97. {
  98. }
  99. // Creates a point with the same values as `src'.
  100. //
  101. inline
  102. AcGePoint3d::AcGePoint3d(const AcGePoint3d& src) : x(src.x), y(src.y), z(src.z)
  103. {
  104. }
  105. // Creates a point intialized to ( xx, yy, zz ).
  106. //
  107. inline
  108. AcGePoint3d::AcGePoint3d(double xx, double yy, double zz) : x(xx), y(yy), z(zz)
  109. {
  110. }
  111. inline bool
  112. AcGePoint3d::operator == (const AcGePoint3d& p) const
  113. {
  114. return this->isEqualTo(p);
  115. }
  116. // This operator is the logical negation of the `==' operator.
  117. //
  118. inline bool
  119. AcGePoint3d::operator != (const AcGePoint3d& p) const
  120. {
  121. return !this->isEqualTo(p);
  122. }
  123. // Returns a point such that each of the coordinates of this point
  124. // have been multiplied by val.
  125. //
  126. inline AcGePoint3d
  127. AcGePoint3d::operator * (double val) const
  128. {
  129. return AcGePoint3d(x*val, y*val, z*val);
  130. }
  131. // Returns a point such that each of the coordinates of this point
  132. // have been multiplied by val.
  133. //
  134. inline AcGePoint3d
  135. operator * (double val, const AcGePoint3d& p)
  136. {
  137. return AcGePoint3d(p.x*val, p.y*val, p.z*val);
  138. }
  139. // This is equivalent to the statement `p = p * val;'
  140. // Each coordinate of this point is multiplied by val.
  141. //
  142. inline AcGePoint3d&
  143. AcGePoint3d::operator *= (double val)
  144. {
  145. x *= val;
  146. y *= val;
  147. z *= val;
  148. return *this;
  149. }
  150. // Returns a point such that each of the coordinates of this point
  151. // have been divided by val.
  152. //
  153. inline AcGePoint3d
  154. AcGePoint3d::operator / (double val) const
  155. {
  156. return AcGePoint3d (x/val, y/val, z/val);
  157. }
  158. // This is equivalent to the statement `p = p / val;'
  159. // Each coordinate of this point is divided by val.
  160. //
  161. inline AcGePoint3d&
  162. AcGePoint3d::operator /= (double val)
  163. {
  164. x /= val;
  165. y /= val;
  166. z /= val;
  167. return *this;
  168. }
  169. // Returns a point that is equivalent to the result of translating
  170. // this point by the vector `v'. (It yields the same result as if
  171. // the vector had been cast to a translation matrix and then
  172. // multiplied with the point.)
  173. //
  174. inline AcGePoint3d
  175. AcGePoint3d::operator + (const AcGeVector3d& v) const
  176. {
  177. return AcGePoint3d (x + v.x, y + v.y, z + v.z);
  178. }
  179. // This is equivalent to the statement `p = p + v;'
  180. //
  181. inline AcGePoint3d&
  182. AcGePoint3d::operator += (const AcGeVector3d& v)
  183. {
  184. x += v.x;
  185. y += v.y;
  186. z += v.z;
  187. return *this;
  188. }
  189. // This is equivalent to the statement `p + (-v);'
  190. //
  191. inline AcGePoint3d
  192. AcGePoint3d::operator - (const AcGeVector3d& v) const
  193. {
  194. return AcGePoint3d (x - v.x, y - v.y, z - v.z);
  195. }
  196. // This is equivalent to the statement `p = p - v;'
  197. //
  198. inline AcGePoint3d&
  199. AcGePoint3d::operator -= (const AcGeVector3d& v)
  200. {
  201. x -= v.x;
  202. y -= v.y;
  203. z -= v.z;
  204. return *this;
  205. }
  206. // This operator returns a vector such that if `v = p1 - p0',
  207. // then, `v' is equivalent to the translation that takes
  208. // `p0' to `p1'. (This point is `p1').
  209. //
  210. inline AcGeVector3d
  211. AcGePoint3d::operator - (const AcGePoint3d& p) const
  212. {
  213. return AcGeVector3d (x - p.x, y - p.y, z - p.z);
  214. }
  215. // This operator returns the vector that would have resulted
  216. // from the operation `p1 - AcGePoint3d::kOrigin', which is
  217. // a common operation to perform.
  218. //
  219. inline AcGeVector3d
  220. AcGePoint3d::asVector() const
  221. {
  222. return AcGeVector3d(x, y, z);
  223. }
  224. // Sets the point to ( xx, yy, zz ).
  225. //
  226. inline AcGePoint3d&
  227. AcGePoint3d::set(double xx, double yy, double zz)
  228. {
  229. x = xx;
  230. y = yy;
  231. z = zz;
  232. return *this;
  233. }
  234. // Indexes the point as if it were an array. `x' is index `0',
  235. // `y' is index `1', `z' is index `2'.
  236. //
  237. inline double
  238. AcGePoint3d::operator [] (unsigned int i) const
  239. {
  240. return *(&x+i);
  241. }
  242. inline double&
  243. AcGePoint3d::operator [] (unsigned int i)
  244. {
  245. return *(&x+i);
  246. }
  247. #define ADSK_ACGEPOINT3D_DEFINED
  248. #include "acarrayhelper.h"
  249. #pragma pack (pop)
  250. #endif