DATAKIT API  V2025.1
dtk_pnt.hpp
Go to the documentation of this file.
1 #ifndef __DTK_PNT_HPP__
2 #define __DTK_PNT_HPP__
3 
4 #include <fstream>
5 #include <math.h>
6 #include "def/define.h"
7 #include <cmath>
8 #include <iosfwd>
9 
10 class Dtk_pnt;
11 class Dtk_dir;
12 class Dtk_string;
13 class Dtk_status;
14 class CDtk_3dMat;
15 
21 class Dtk_pnt
22 {
23 protected:
24  double _Coords[ 3 ];
25 public:
28  ~Dtk_pnt() {}
30  Dtk_pnt( const Dtk_pnt& s );
32  Dtk_pnt( double a, double b, double c = 0.0 );
34  Dtk_pnt( const double d[] );
35  Dtk_pnt& operator = ( const Dtk_pnt& s );
40  inline double& operator[] ( Dtk_Size_t i )
41  {
42  Pdtk_Assert( i < 3 );
43  return _Coords[ i ];
44  }
50  inline const double& operator[] ( Dtk_Size_t i ) const
51  {
52  Pdtk_Assert( i < 3 );
53  return _Coords[ i ];
54  }
55 
57  inline double & x() { return _Coords[ 0 ]; }
58 
61  inline const double & x() const { return _Coords[ 0 ]; }
62 
64  inline double & y() { return _Coords[ 1 ]; }
65 
68  inline const double & y() const { return _Coords[ 1 ]; }
69 
71  inline double & z() { return _Coords[ 2 ]; }
72 
75  inline const double & z() const { return _Coords[ 2 ]; }
76 
79  inline void GetXYZ( Dtk_Double64& outX, Dtk_Double64& outY, Dtk_Double64& outZ ) const
80  {
81  outX = _Coords[ 0 ];
82  outY = _Coords[ 1 ];
83  outZ = _Coords[ 2 ];
84  }
85 
87  inline void SetXYZ( const Dtk_Double64& inX, const Dtk_Double64& inY, const Dtk_Double64& inZ )
88  {
89  _Coords[ 0 ] = inX;
90  _Coords[ 1 ] = inY;
91  _Coords[ 2 ] = inZ;
92  }
93 
94  Dtk_pnt& operator*=( double );
95  Dtk_pnt& operator/=( double );
129  friend Dtk_pnt operator+( const Dtk_pnt&, const Dtk_dir& ); // pour barycentre
142  friend Dtk_dir operator-( const Dtk_pnt&, const Dtk_dir& );
143 
144  inline Dtk_pnt operator* ( double a ) const { return Dtk_pnt( _Coords[ 0 ] * a, _Coords[ 1 ] * a, _Coords[ 2 ] * a ); }
145  friend Dtk_pnt operator* ( double, const Dtk_pnt& );
146  friend Dtk_pnt operator/ ( const Dtk_pnt&, double );
147  friend Dtk_pnt operator/ ( double, const Dtk_pnt& );
148 
162  friend int operator==( const Dtk_pnt&, const Dtk_pnt& );
176  friend int operator!=( const Dtk_pnt&, const Dtk_pnt& );
177 
191  int IsEqual( const Dtk_pnt& inPointToCompare, const double inTolerance ) const;
192  // Dtk_pnt operator=(double d[]); // inutile
193 
194  inline static void ProcessMiddlePoint( const Dtk_pnt& inPntA, const Dtk_pnt& inPntB, Dtk_pnt& outMiddlePnt )
195  {
196  for( Dtk_Size_t i = 0; i < 3; i++ )
197  outMiddlePnt[ i ] = ( inPntA[ i ] + inPntB[ i ] ) / 2.0;
198  }
199 
200  inline static Dtk_Double64 ProcessDistance( const Dtk_pnt& inPoint1, const Dtk_pnt& inPoint2 )
201  {
202  Dtk_Double64 dist = 0.0;
203  Dtk_Size_t i;
204 
205  for( i = 0; i < 3; i++ )
206  dist += ( inPoint1[ i ] - inPoint2[ i ] ) * ( inPoint1[ i ] - inPoint2[ i ] );
207 
208  return static_cast< Dtk_Double64 >( sqrt( dist ) );
209  }
210 
211  /* void SetInvalid();
212  Dtk_bool IsInvalid()const;*/
213 
214  friend std::ostream& operator<<( std::ostream& o, const Dtk_pnt& d );
215 
216  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_dir& y, const Dtk_pnt& P );
217  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_pnt& P );
218  friend double Argument( const Dtk_pnt& P );
219 
220  double Solve( const Dtk_dir& col0, const Dtk_dir& col1, const Dtk_dir& col2, const Dtk_dir& col3 );
221  double Solve( const CDtk_3dMat& matrix, const Dtk_dir& col3 );
222  void Multiply( const CDtk_3dMat& matrix );
223  inline void operator *= ( const CDtk_3dMat& matrix );
224  Dtk_pnt Multiplied( const CDtk_3dMat& matrix ) const;
225  inline Dtk_pnt operator * ( const CDtk_3dMat& matrix ) const;
226  void PostMultiply( const CDtk_3dMat& matrix );
227  Dtk_pnt PostMultiplied( const CDtk_3dMat& matrix ) const;
228 
229  void MultiplyByTransposed( const CDtk_3dMat& matrix );
230  Dtk_pnt MultipliedByTransposed( const CDtk_3dMat& matrix ) const;
231 
232  double Project( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj );
233  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj ) const;
234  double Project( const Dtk_pnt& org, const Dtk_dir& zdir );
235  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir ) const;
236  double Project( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj );
237  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj ) const;
238  double Project( const Dtk_dir& zdir, double d );
239  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d ) const;
240  void ProjectOnLine( const Dtk_pnt& org, const Dtk_dir& dir );
241  inline Dtk_pnt ProjectedOnLine( const Dtk_pnt& org, const Dtk_dir& dir ) const;
242 
243  void Scale( const Dtk_pnt& p0, double s );
244  Dtk_pnt Scaled( const Dtk_pnt& p0, double s ) const;
245  void Translate( const Dtk_dir& dir );
246  Dtk_pnt Translated( const Dtk_dir& dir ) const;
247  void Translate( const Dtk_pnt& p0, const Dtk_pnt& p1 );
248  Dtk_pnt Translated( const Dtk_pnt& p0, const Dtk_pnt& p1 ) const;
249  void Transform( const CDtk_3dMat& matrix );
250  Dtk_pnt Transformed( const CDtk_3dMat& matrix ) const;
251  void Rotate( const Dtk_pnt& p0, const CDtk_3dMat& matrix );
252  Dtk_pnt Rotated( const Dtk_pnt& p0, const CDtk_3dMat& matrix ) const;
253  void Rotate( const Dtk_dir& dir, double angle, const Dtk_pnt& center );
254  Dtk_pnt Rotated( const Dtk_dir& dir, double angle, const Dtk_pnt& center ) const;
255  void Symetry( const Dtk_dir& zpl );
256  void Symetry( const Dtk_pnt& opl, const Dtk_dir& zpl );
257  Dtk_pnt Symetrised( const Dtk_pnt& opl, const Dtk_dir& zpl ) const;
258  void Affinity( const Dtk_pnt&, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] );
259  inline void Affinity( double f[ 3 ] ) { _Coords[ 0 ] *= f[ 0 ]; _Coords[ 1 ] *= f[ 1 ]; _Coords[ 2 ] *= f[ 2 ]; }
260  Dtk_pnt Affinitised( const Dtk_pnt& p, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] ) const;
261 };
262 
263 inline void Dtk_pnt::operator *= ( const CDtk_3dMat& matrix )
264 {
265  Multiply( matrix );
266 }
267 
268 inline Dtk_pnt Dtk_pnt::operator * ( const CDtk_3dMat& matrix ) const
269 {
270  return Multiplied( matrix );
271 }
272 
273 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zprj ) const
274 {
275  Dtk_pnt tmp = *this;
276  tmp.Project( org, zdir, zprj );
277  return tmp;
278 }
279 
280 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_pnt& org, const Dtk_dir& zdir ) const
281 {
282  Dtk_pnt tmp = *this;
283  tmp.Project( org, zdir );
284  return tmp;
285 }
286 
287 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_dir& zdir, double d, const Dtk_dir& zprj ) const
288 {
289  Dtk_pnt tmp = *this;
290  tmp.Project( zdir, d, zprj );
291  return tmp;
292 }
293 
294 inline Dtk_pnt Dtk_pnt::Projected( const Dtk_dir& zdir, double d ) const
295 {
296  Dtk_pnt tmp = *this;
297  tmp.Project( zdir, d );
298  return tmp;
299 }
300 
301 inline Dtk_pnt Dtk_pnt::ProjectedOnLine( const Dtk_pnt& org, const Dtk_dir& dir ) const
302 {
303  Dtk_pnt tmp = *this;
304  tmp.ProjectOnLine( org, dir );
305  return tmp;
306 }
307 
308 #endif
Dtk_pnt::x
const double & x() const
access to x coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:61
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:200
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:58
Dtk_pnt::operator/=
Dtk_pnt & operator/=(double)
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
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:64
Dtk_pnt::operator*
Dtk_pnt operator*(double a) const
Definition: dtk_pnt.hpp:144
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:699
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:87
Dtk_pnt::Solve
double Solve(const CDtk_3dMat &matrix, const Dtk_dir &col3)
Pdtk_Assert
#define Pdtk_Assert(X)
Definition: define.h:742
Dtk_pnt::Affinity
void Affinity(double f[3])
Definition: dtk_pnt.hpp:259
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:71
Dtk_pnt::~Dtk_pnt
~Dtk_pnt()
Definition: dtk_pnt.hpp:28
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:301
Dtk_pnt::y
const double & y() const
access to y coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:68
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:40
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:57
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:22
Dtk_pnt::Projected
Dtk_pnt Projected(const Dtk_pnt &org, const Dtk_dir &zdir, const Dtk_dir &zPrj) const
Definition: dtk_pnt.hpp:273
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:75
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:194
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:79
Dtk_pnt::_Coords
double _Coords[3]
Definition: dtk_pnt.hpp:24
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:15
Dtk_pnt::Symetrised
Dtk_pnt Symetrised(const Dtk_pnt &opl, const Dtk_dir &zpl) const