DATAKIT SDK  V2026.1
dtk_pnt.hpp
Go to the documentation of this file.
1 #ifndef __DTK_PNT_HPP__
2 #define __DTK_PNT_HPP__
3 
4 #include "def/define.h"
5 #include <cmath>
6 #include <iosfwd>
7 
8 class Dtk_pnt;
9 class Dtk_dir;
10 class Dtk_string;
11 class Dtk_status;
12 class CDtk_3dMat;
13 
19 class Dtk_pnt
20 {
21 protected:
22  double _Coords[ 3 ];
23 public:
26  ~Dtk_pnt() {}
28  Dtk_pnt( const Dtk_pnt& s );
30  Dtk_pnt( double a, double b, double c = 0.0 );
32  Dtk_pnt( const double d[] );
33  Dtk_pnt& operator = ( const Dtk_pnt& s );
38  inline double& operator[] ( Dtk_Size_t i )
39  {
40  Pdtk_Assert( i < 3 );
41  return _Coords[ i ];
42  }
48  inline const double& operator[] ( Dtk_Size_t i ) const
49  {
50  Pdtk_Assert( i < 3 );
51  return _Coords[ i ];
52  }
53 
55  inline double & x() { return _Coords[ 0 ]; }
56 
59  inline const double & x() const { return _Coords[ 0 ]; }
60 
62  inline double & y() { return _Coords[ 1 ]; }
63 
66  inline const double & y() const { return _Coords[ 1 ]; }
67 
69  inline double & z() { return _Coords[ 2 ]; }
70 
73  inline const double & z() const { return _Coords[ 2 ]; }
74 
77  inline void GetXYZ( Dtk_Double64& outX, Dtk_Double64& outY, Dtk_Double64& outZ ) const
78  {
79  outX = _Coords[ 0 ];
80  outY = _Coords[ 1 ];
81  outZ = _Coords[ 2 ];
82  }
83 
85  inline void SetXYZ( const Dtk_Double64& inX, const Dtk_Double64& inY, const Dtk_Double64& inZ )
86  {
87  _Coords[ 0 ] = inX;
88  _Coords[ 1 ] = inY;
89  _Coords[ 2 ] = inZ;
90  }
91 
92  Dtk_pnt& operator*=( double );
93  Dtk_pnt& operator/=( double );
127  friend Dtk_pnt operator+( const Dtk_pnt&, const Dtk_dir& ); // pour barycentre
140  friend Dtk_dir operator-( const Dtk_pnt&, const Dtk_dir& );
141 
142  inline Dtk_pnt operator* ( double a ) const { return Dtk_pnt( _Coords[ 0 ] * a, _Coords[ 1 ] * a, _Coords[ 2 ] * a ); }
143  friend Dtk_pnt operator* ( double, const Dtk_pnt& );
144  friend Dtk_pnt operator/ ( const Dtk_pnt&, double );
145  friend Dtk_pnt operator/ ( double, const Dtk_pnt& );
146 
160  friend int operator==( const Dtk_pnt&, const Dtk_pnt& );
174  friend int operator!=( const Dtk_pnt&, const Dtk_pnt& );
175 
189  int IsEqual( const Dtk_pnt& inPointToCompare, const double inTolerance ) const;
190  // Dtk_pnt operator=(double d[]); // inutile
191 
192  inline static void ProcessMiddlePoint( const Dtk_pnt& inPntA, const Dtk_pnt& inPntB, Dtk_pnt& outMiddlePnt )
193  {
194  for( Dtk_Size_t i = 0; i < 3; i++ )
195  outMiddlePnt[ i ] = ( inPntA[ i ] + inPntB[ i ] ) / 2.0;
196  }
197 
198  inline static Dtk_Double64 ProcessDistance( const Dtk_pnt& inPoint1, const Dtk_pnt& inPoint2 )
199  {
200  Dtk_Double64 dist = 0.0;
201  Dtk_Size_t i;
202 
203  for( i = 0; i < 3; i++ )
204  dist += ( inPoint1[ i ] - inPoint2[ i ] ) * ( inPoint1[ i ] - inPoint2[ i ] );
205 
206  return static_cast< Dtk_Double64 >( sqrt( dist ) );
207  }
208 
209  /* void SetInvalid();
210  Dtk_bool IsInvalid()const;*/
211 
212  friend std::ostream& operator<<( std::ostream& o, const Dtk_pnt& d );
213 
214  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_dir& y, const Dtk_pnt& P );
215  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_pnt& P );
216  friend double Argument( const Dtk_pnt& P );
217 
218  double Solve( const Dtk_dir& col0, const Dtk_dir& col1, const Dtk_dir& col2, const Dtk_dir& col3 );
219  double Solve( const CDtk_3dMat& matrix, const Dtk_dir& col3 );
220  void Multiply( const CDtk_3dMat& matrix );
221  inline void operator *= ( const CDtk_3dMat& matrix );
222  Dtk_pnt Multiplied( const CDtk_3dMat& matrix ) const;
223  inline Dtk_pnt operator * ( const CDtk_3dMat& matrix ) const;
224  void PostMultiply( const CDtk_3dMat& matrix );
225  Dtk_pnt PostMultiplied( const CDtk_3dMat& matrix ) const;
226 
227  void MultiplyByTransposed( const CDtk_3dMat& matrix );
228  Dtk_pnt MultipliedByTransposed( const CDtk_3dMat& matrix ) const;
229 
230  double Project( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj );
231  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj ) const;
232  double Project( const Dtk_pnt& org, const Dtk_dir& zdir );
233  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir ) const;
234  double Project( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj );
235  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj ) const;
236  double Project( const Dtk_dir& zdir, double d );
237  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d ) const;
238  void ProjectOnLine( const Dtk_pnt& org, const Dtk_dir& dir );
239  inline Dtk_pnt ProjectedOnLine( const Dtk_pnt& org, const Dtk_dir& dir ) const;
240 
241  void Scale( const Dtk_pnt& p0, double s );
242  Dtk_pnt Scaled( const Dtk_pnt& p0, double s ) const;
243  void Translate( const Dtk_dir& dir );
244  Dtk_pnt Translated( const Dtk_dir& dir ) const;
245  void Translate( const Dtk_pnt& p0, const Dtk_pnt& p1 );
246  Dtk_pnt Translated( const Dtk_pnt& p0, const Dtk_pnt& p1 ) const;
247  void Transform( const CDtk_3dMat& matrix );
248  Dtk_pnt Transformed( const CDtk_3dMat& matrix ) const;
249  void Rotate( const Dtk_pnt& p0, const CDtk_3dMat& matrix );
250  Dtk_pnt Rotated( const Dtk_pnt& p0, const CDtk_3dMat& matrix ) const;
251  void Rotate( const Dtk_dir& dir, double angle, const Dtk_pnt& center );
252  Dtk_pnt Rotated( const Dtk_dir& dir, double angle, const Dtk_pnt& center ) const;
253  void Symetry( const Dtk_dir& zpl );
254  void Symetry( const Dtk_pnt& opl, const Dtk_dir& zpl );
255  Dtk_pnt Symetrised( const Dtk_pnt& opl, const Dtk_dir& zpl ) const;
256  void Affinity( const Dtk_pnt&, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] );
257  inline void Affinity( double f[ 3 ] ) { _Coords[ 0 ] *= f[ 0 ]; _Coords[ 1 ] *= f[ 1 ]; _Coords[ 2 ] *= f[ 2 ]; }
258  Dtk_pnt Affinitised( const Dtk_pnt& p, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] ) const;
259 };
260 
261 inline void Dtk_pnt::operator *= ( const CDtk_3dMat& matrix )
262 {
263  Multiply( matrix );
264 }
265 
266 inline Dtk_pnt Dtk_pnt::operator * ( const CDtk_3dMat& matrix ) const
267 {
268  return Multiplied( matrix );
269 }
270 
271 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zprj ) const
272 {
273  Dtk_pnt tmp = *this;
274  tmp.Project( org, zdir, zprj );
275  return tmp;
276 }
277 
278 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_pnt& org, const Dtk_dir& zdir ) const
279 {
280  Dtk_pnt tmp = *this;
281  tmp.Project( org, zdir );
282  return tmp;
283 }
284 
285 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_dir& zdir, double d, const Dtk_dir& zprj ) const
286 {
287  Dtk_pnt tmp = *this;
288  tmp.Project( zdir, d, zprj );
289  return tmp;
290 }
291 
292 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_dir& zdir, double d ) const
293 {
294  Dtk_pnt tmp = *this;
295  tmp.Project( zdir, d );
296  return tmp;
297 }
298 
299 inline Dtk_pnt Dtk_pnt::ProjectedOnLine( const Dtk_pnt& org, const Dtk_dir& dir ) const
300 {
301  Dtk_pnt tmp = *this;
302  tmp.ProjectOnLine( org, dir );
303  return tmp;
304 }
305 
306 #endif
Dtk_pnt::x
const double & x() const
access to x coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:59
Dtk_pnt::Symetry
void Symetry(const Dtk_pnt &opl, const Dtk_dir &zpl)
Dtk_pnt::operator*=
Dtk_pnt & operator*=(double)
Dtk_pnt::operator<<
friend std::ostream & operator<<(std::ostream &o, const Dtk_pnt &d)
Dtk_pnt::operator==
friend int operator==(const Dtk_pnt &, const Dtk_pnt &)
test if 2 Dtk_pnt are equal
Dtk_pnt::ProcessDistance
static Dtk_Double64 ProcessDistance(const Dtk_pnt &inPoint1, const Dtk_pnt &inPoint2)
Definition: dtk_pnt.hpp:198
Dtk_pnt::Argument
friend double Argument(const Dtk_pnt &O, const Dtk_dir &x, const Dtk_pnt &P)
Dtk_pnt::PostMultiply
void PostMultiply(const CDtk_3dMat &matrix)
Dtk_pnt::Translate
void Translate(const Dtk_pnt &p0, const Dtk_pnt &p1)
Dtk_pnt::Solve
double Solve(const Dtk_dir &col0, const Dtk_dir &col1, const Dtk_dir &col2, const Dtk_dir &col3)
Dtk_pnt::operator-=
Dtk_pnt & operator-=(const Dtk_dir &)
translate (in the opposite direction) the Dtk_pnt with the given Dtk_dir
Dtk_pnt::operator-
friend Dtk_dir operator-(const Dtk_pnt &, const Dtk_dir &)
translate (in the opposite direction) a Dtk_pnt with a Dtk_dir
Dtk_pnt::Project
double Project(const Dtk_dir &zdir, double d, const Dtk_dir &zPrj)
Dtk_pnt::Argument
friend double Argument(const Dtk_pnt &O, const Dtk_dir &x, const Dtk_dir &y, const Dtk_pnt &P)
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:53
Dtk_pnt::operator/=
Dtk_pnt & operator/=(double)
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:715
Dtk_pnt::IsEqual
int IsEqual(const Dtk_pnt &inPointToCompare, const double inTolerance) const
test if 2 Dtk_pnt are equal - with a tolerance -
Dtk_pnt::Symetry
void Symetry(const Dtk_dir &zpl)
Dtk_pnt::Affinity
void Affinity(const Dtk_pnt &, const Dtk_dir &xdir, const Dtk_dir &ydir, double f[3])
Dtk_pnt::operator-
Dtk_pnt operator-()
Dtk_pnt::Multiplied
Dtk_pnt Multiplied(const CDtk_3dMat &matrix) const
Dtk_pnt::ProjectOnLine
void ProjectOnLine(const Dtk_pnt &org, const Dtk_dir &dir)
Dtk_pnt::y
double & y()
access to y coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:62
Dtk_pnt::operator*
Dtk_pnt operator*(double a) const
Definition: dtk_pnt.hpp:142
Dtk_pnt::Project
double Project(const Dtk_pnt &org, const Dtk_dir &zdir, const Dtk_dir &zPrj)
Dtk_status
Definition: dtk_status.hpp:16
Dtk_pnt::Rotate
void Rotate(const Dtk_pnt &p0, const CDtk_3dMat &matrix)
Dtk_pnt::Project
double Project(const Dtk_dir &zdir, double d)
Dtk_pnt::Rotate
void Rotate(const Dtk_dir &dir, double angle, const Dtk_pnt &center)
Dtk_pnt::Dtk_pnt
Dtk_pnt()
default constructor
Dtk_pnt::Rotated
Dtk_pnt Rotated(const Dtk_dir &dir, double angle, const Dtk_pnt &center) const
Dtk_Double64
double Dtk_Double64
Definition: define.h:702
Dtk_pnt::Scaled
Dtk_pnt Scaled(const Dtk_pnt &p0, double s) const
Dtk_pnt::operator/
friend Dtk_pnt operator/(const Dtk_pnt &, double)
Dtk_pnt::Affinitised
Dtk_pnt Affinitised(const Dtk_pnt &p, const Dtk_dir &xdir, const Dtk_dir &ydir, double f[3]) const
Dtk_pnt::operator!=
friend int operator!=(const Dtk_pnt &, const Dtk_pnt &)
test if 2 Dtk_pnt are different
Dtk_pnt::SetXYZ
void SetXYZ(const Dtk_Double64 &inX, const Dtk_Double64 &inY, const Dtk_Double64 &inZ)
Sets the 3 coordinates of the class.
Definition: dtk_pnt.hpp:85
Dtk_pnt::Solve
double Solve(const CDtk_3dMat &matrix, const Dtk_dir &col3)
Pdtk_Assert
#define Pdtk_Assert(X)
Definition: define.h:746
Dtk_pnt::Affinity
void Affinity(double f[3])
Definition: dtk_pnt.hpp:257
Dtk_pnt::Scale
void Scale(const Dtk_pnt &p0, double s)
Dtk_pnt::PostMultiplied
Dtk_pnt PostMultiplied(const CDtk_3dMat &matrix) const
Dtk_pnt::z
double & z()
access to z coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:69
Dtk_pnt::~Dtk_pnt
~Dtk_pnt()
Definition: dtk_pnt.hpp:26
Dtk_pnt::Rotated
Dtk_pnt Rotated(const Dtk_pnt &p0, const CDtk_3dMat &matrix) const
Dtk_pnt::ProjectedOnLine
Dtk_pnt ProjectedOnLine(const Dtk_pnt &org, const Dtk_dir &dir) const
Definition: dtk_pnt.hpp:299
Dtk_pnt::y
const double & y() const
access to y coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:66
Dtk_pnt::Project
double Project(const Dtk_pnt &org, const Dtk_dir &zdir)
Dtk_pnt::operator=
Dtk_pnt & operator=(const Dtk_pnt &s)
Dtk_pnt::operator[]
double & operator[](Dtk_Size_t i)
access to a specified coordinate of the Dtk_pnt
Definition: dtk_pnt.hpp:38
Dtk_pnt::MultiplyByTransposed
void MultiplyByTransposed(const CDtk_3dMat &matrix)
Dtk_pnt::Translate
void Translate(const Dtk_dir &dir)
Dtk_pnt::Dtk_pnt
Dtk_pnt(const Dtk_pnt &s)
copy constructor
Dtk_pnt::Transformed
Dtk_pnt Transformed(const CDtk_3dMat &matrix) const
Dtk_pnt::x
double & x()
access to x coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:55
Dtk_pnt::Argument
friend double Argument(const Dtk_pnt &P)
Dtk_pnt::Translated
Dtk_pnt Translated(const Dtk_dir &dir) const
Dtk_pnt
This is a mathematical point class.
Definition: dtk_pnt.hpp:20
Dtk_pnt::Projected
Dtk_pnt Projected(const Dtk_pnt &org, const Dtk_dir &zdir, const Dtk_dir &zPrj) const
Definition: dtk_pnt.hpp:271
Dtk_pnt::Translated
Dtk_pnt Translated(const Dtk_pnt &p0, const Dtk_pnt &p1) const
Dtk_pnt::Transform
void Transform(const CDtk_3dMat &matrix)
Dtk_pnt::operator+=
Dtk_pnt & operator+=(const Dtk_dir &)
translate the Dtk_pnt with the given Dtk_dir
Dtk_pnt::z
const double & z() const
access to z coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:73
define.h
Dtk_pnt::Dtk_pnt
Dtk_pnt(double a, double b, double c=0.0)
constructor from 3 double
Dtk_pnt::operator+
friend Dtk_pnt operator+(const Dtk_pnt &, const Dtk_dir &)
translate a Dtk_pnt with a Dtk_dir
Dtk_pnt::MultipliedByTransposed
Dtk_pnt MultipliedByTransposed(const CDtk_3dMat &matrix) const
Dtk_pnt::Multiply
void Multiply(const CDtk_3dMat &matrix)
Dtk_pnt::ProcessMiddlePoint
static void ProcessMiddlePoint(const Dtk_pnt &inPntA, const Dtk_pnt &inPntB, Dtk_pnt &outMiddlePnt)
Definition: dtk_pnt.hpp:192
Dtk_pnt::GetXYZ
void GetXYZ(Dtk_Double64 &outX, Dtk_Double64 &outY, Dtk_Double64 &outZ) const
Retrieves to the 3 coordinates of the class.
Definition: dtk_pnt.hpp:77
Dtk_pnt::_Coords
double _Coords[3]
Definition: dtk_pnt.hpp:22
Dtk_pnt::Dtk_pnt
Dtk_pnt(const double d[])
constructor from a 3 double array
Dtk_dir
This is a mathematical direction class.
Definition: dtk_dir.hpp:14
Dtk_pnt::Symetrised
Dtk_pnt Symetrised(const Dtk_pnt &opl, const Dtk_dir &zpl) const