DATAKIT SDK  V2026.4
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 "dtk/config.hpp"
6 #include <cmath>
7 #include <iosfwd>
8 
9 class Dtk_pnt;
10 class Dtk_dir;
11 class Dtk_string;
12 class CDtk_3dMat;
13 
14 //! \ingroup base_types
15 //! \class Dtk_pnt
16 //! \brief This is a mathematical point class.
17 //!
18 //! This class provides all method about points
19 class Dtk_pnt
20 {
21 protected:
22  double _Coords[ 3 ];
23 public:
24  //! \brief default constructor
26  ~Dtk_pnt() {}
27  //! \brief copy constructor
28  Dtk_pnt( const Dtk_pnt& s );
30  //! \brief constructor from 3 double
31  Dtk_pnt( double a, double b, double c = 0.0 );
32  //! \brief constructor from a 3 double array
33  Dtk_pnt( const double d[] );
34  Dtk_pnt& operator = ( const Dtk_pnt& s );
35  //! \brief access to a specified coordinate of the Dtk_pnt
36  //! - i = 0 => X coordinate
37  //! - i = 1 => Y coordinate
38  //! - i = 2 => Z coordinate
39  inline double& operator[] ( Dtk_Size_t i )
40  {
41  Pdtk_Assert( i < 3 );
42  return _Coords[ i ];
43  }
44  //! \brief access to a specified coordinate of the Dtk_pnt.
45  //! \warning You can't modify the returned value.
46  //! - i = 0 => X coordinate
47  //! - i = 1 => Y coordinate
48  //! - i = 2 => Z coordinate
49  inline const double& operator[] ( Dtk_Size_t i ) const
50  {
51  Pdtk_Assert( i < 3 );
52  return _Coords[ i ];
53  }
54 
55  //! \brief access to x coordinate of the Dtk_pnt.
56  inline double & x() { return _Coords[ 0 ]; }
57 
58  //! \brief access to x coordinate of the Dtk_pnt.
59  //! \warning You can't modify the returned value.
60  inline const double & x() const { return _Coords[ 0 ]; }
61 
62  //! \brief access to y coordinate of the Dtk_pnt.
63  inline double & y() { return _Coords[ 1 ]; }
64 
65  //! \brief access to y coordinate of the Dtk_pnt.
66  //! \warning You can't modify the returned value.
67  inline const double & y() const { return _Coords[ 1 ]; }
68 
69  //! \brief access to z coordinate of the Dtk_pnt.
70  inline double & z() { return _Coords[ 2 ]; }
71 
72  //! \brief access to z coordinate of the Dtk_pnt.
73  //! \warning You can't modify the returned value.
74  inline const double & z() const { return _Coords[ 2 ]; }
75 
76  //! \brief Retrieves to the 3 coordinates of the class.
77  //! \warning You can't modify the returned value.
78  inline void GetXYZ( Dtk_Double64& outX, Dtk_Double64& outY, Dtk_Double64& outZ ) const
79  {
80  outX = _Coords[ 0 ];
81  outY = _Coords[ 1 ];
82  outZ = _Coords[ 2 ];
83  }
84 
85  //! \brief Sets the 3 coordinates of the class.
86  inline void SetXYZ( const Dtk_Double64& inX, const Dtk_Double64& inY, const Dtk_Double64& inZ )
87  {
88  _Coords[ 0 ] = inX;
89  _Coords[ 1 ] = inY;
90  _Coords[ 2 ] = inZ;
91  }
92 
93  Dtk_pnt& operator*=( double );
94  Dtk_pnt& operator/=( double );
96  //! \brief translate the Dtk_pnt with the given Dtk_dir
97  //! \param a the translation direction
98  //!
99  //! \b Sample:
100  //! \code
101  //! Dtk_pnt a(0.0,0.0,0.0);
102  //! Dtk_dir b(15.0,0.0,0.0);
103  //! a += b; //Now a is (15.0,0.0,0.0)
104  //! \endcode
106  //! \brief translate (in the opposite direction) the Dtk_pnt with the given Dtk_dir
107  //! \param a the translation direction
108  //!
109  //! \b Sample:
110  //! \code
111  //! Dtk_pnt a(0.0,0.0,0.0);
112  //! Dtk_dir b(15.0,0.0,0.0);
113  //! a -= b; //Now a is (-15.0,0.0,0.0)
114  //! \endcode
116  //! \brief translate a Dtk_pnt with a Dtk_dir
117  //! \param u the point to translate
118  //! \param v the translation direction
119  //! \return the translated point
120  //!
121  //! \b Sample:
122  //! \code
123  //! Dtk_pnt a(0.0,0.0,0.0);
124  //! Dtk_dir b(15.0,0.0,0.0);
125  //! Dtk_pnt c;
126  //! c = a + b; //Now c is (15.0,0.0,0.0)
127  //! \endcode
128  friend Dtk_pnt operator+( const Dtk_pnt&, const Dtk_dir& ); // pour barycentre
129  //! \brief translate (in the opposite direction) a Dtk_pnt with a Dtk_dir
130  //! \param u the point to translate
131  //! \param v the translation direction
132  //! \return the translated point
133  //!
134  //! \b Sample:
135  //! \code
136  //! Dtk_pnt a(0.0,0.0,0.0);
137  //! Dtk_dir b(15.0,0.0,0.0);
138  //! Dtk_pnt c;
139  //! c = a - b; //Now c is (-15.0,0.0,0.0)
140  //! \endcode
141  friend Dtk_dir operator-( const Dtk_pnt&, const Dtk_dir& );
142 
143  inline Dtk_pnt operator* ( double a ) const { return Dtk_pnt( _Coords[ 0 ] * a, _Coords[ 1 ] * a, _Coords[ 2 ] * a ); }
144  friend Dtk_pnt operator* ( double, const Dtk_pnt& );
145  friend Dtk_pnt operator/ ( const Dtk_pnt&, double );
146  friend Dtk_pnt operator/ ( double, const Dtk_pnt& );
147 
148  //! \brief test if 2 Dtk_pnt are equal
149  //! \param u the first Dtk_pnt
150  //! \param v the second Dtk_pnt
151  //! \return 0 if not equals != 0 else
152  //!
153  //! \b Sample:
154  //! \code
155  //! Dtk_pnt a(0.0,0.0,0.0);
156  //! Dtk_pnt b(15.0,0.0,0.0);
157  //! ...
158  //! if(a == b)
159  //! {...}
160  //! \endcode
161  friend int operator==( const Dtk_pnt&, const Dtk_pnt& );
162  //! \brief test if 2 Dtk_pnt are different
163  //! \param u the first Dtk_pnt
164  //! \param v the second Dtk_pnt
165  //! \return 0 if equals != 0 else
166  //!
167  //! \b Sample:
168  //! \code
169  //! Dtk_pnt a(0.0,0.0,0.0);
170  //! Dtk_pnt b(15.0,0.0,0.0);
171  //! ...
172  //! if(a != b)
173  //! {...}
174  //! \endcode
175  friend int operator!=( const Dtk_pnt&, const Dtk_pnt& );
176 
177  //! \brief test if 2 Dtk_pnt are equal - with a tolerance -
178  //! \param pnt2 the Dtk_pnt to compare
179  //! \param tol the tolerance to compare
180  //! \return 0 if not equals != 0 else
181  //!
182  //! \b Sample:
183  //! \code
184  //! Dtk_pnt a(0.0,0.0,0.0);
185  //! Dtk_pnt b(15.0,0.0,0.0);
186  //! ...
187  //! if(a.is_equal(b, 0.1))
188  //! {...}
189  //! \endcode
190  int IsEqual( const Dtk_pnt& inPointToCompare, const double inTolerance ) const;
191  // Dtk_pnt operator=(double d[]); // inutile
192 
193  static void ProcessMiddlePoint( const Dtk_pnt& inPntA, const Dtk_pnt& inPntB, Dtk_pnt& outMiddlePnt )
194  {
195  for( Dtk_Size_t i = 0; i < 3; i++ )
196  outMiddlePnt[ i ] = ( inPntA[ i ] + inPntB[ i ] ) / 2.0;
197  }
198 
199  static Dtk_Double64 ProcessDistance( const Dtk_pnt& inPoint1, const Dtk_pnt& inPoint2 )
200  {
201  Dtk_Double64 dist = 0.0;
202  Dtk_Size_t i;
203 
204  for( i = 0; i < 3; i++ )
205  dist += ( inPoint1[ i ] - inPoint2[ i ] ) * ( inPoint1[ i ] - inPoint2[ i ] );
206 
207  return static_cast< Dtk_Double64 >( sqrt( dist ) );
208  }
209 
210  /* void SetInvalid();
211  Dtk_bool IsInvalid()const;*/
212 
213  friend std::ostream& operator<<( std::ostream& o, const Dtk_pnt& d );
214 
215  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_dir& y, const Dtk_pnt& P );
216  friend double Argument( const Dtk_pnt& O, const Dtk_dir& x, const Dtk_pnt& P );
217  friend double Argument( const Dtk_pnt& P );
218 
219  double Solve( const Dtk_dir& col0, const Dtk_dir& col1, const Dtk_dir& col2, const Dtk_dir& col3 );
220  double Solve( const CDtk_3dMat& matrix, const Dtk_dir& col3 );
221  void Multiply( const CDtk_3dMat& matrix );
222  inline void operator *= ( const CDtk_3dMat& matrix ){ Multiply( matrix ); };
223  Dtk_pnt Multiplied( const CDtk_3dMat& matrix ) const;
224  inline Dtk_pnt operator * ( const CDtk_3dMat& matrix ) const { return Multiplied( matrix ); };
225  void PostMultiply( const CDtk_3dMat& matrix );
226  Dtk_pnt PostMultiplied( const CDtk_3dMat& matrix ) const;
227 
228  void MultiplyByTransposed( const CDtk_3dMat& matrix );
229  Dtk_pnt MultipliedByTransposed( const CDtk_3dMat& matrix ) const;
230 
231  double Project( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj );
232  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir, const Dtk_dir& zPrj ) const { Dtk_pnt tmp = *this; tmp.Project( org, zdir, zPrj ); return tmp; };
233  double Project( const Dtk_pnt& org, const Dtk_dir& zdir );
234  inline Dtk_pnt Projected( const Dtk_pnt& org, const Dtk_dir& zdir ) const { Dtk_pnt tmp = *this; tmp.Project( org, zdir ); return tmp; };
235  double Project( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj );
236  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d, const Dtk_dir& zPrj ) const { Dtk_pnt tmp = *this; tmp.Project( zdir, d, zPrj ); return tmp; };
237  double Project( const Dtk_dir& zdir, double d );
238  inline Dtk_pnt Projected( const Dtk_dir& zdir, double d ) const { Dtk_pnt tmp = *this; tmp.Project( zdir, d ); return tmp; };
239  void ProjectOnLine( const Dtk_pnt& org, const Dtk_dir& dir );
240  inline Dtk_pnt ProjectedOnLine( const Dtk_pnt& org, const Dtk_dir& dir ) const { Dtk_pnt tmp = *this; tmp.ProjectOnLine( org, dir ); return tmp; };
241 
242  void Scale( const Dtk_pnt& p0, double s );
243  Dtk_pnt Scaled( const Dtk_pnt& p0, double s ) const;
244  void Translate( const Dtk_dir& dir );
245  Dtk_pnt Translated( const Dtk_dir& dir ) const;
246  void Translate( const Dtk_pnt& p0, const Dtk_pnt& p1 );
247  Dtk_pnt Translated( const Dtk_pnt& p0, const Dtk_pnt& p1 ) const;
248  void Transform( const CDtk_3dMat& matrix );
249  Dtk_pnt Transformed( const CDtk_3dMat& matrix ) const;
250  void Rotate( const Dtk_pnt& p0, const CDtk_3dMat& matrix );
251  Dtk_pnt Rotated( const Dtk_pnt& p0, const CDtk_3dMat& matrix ) const;
252  void Rotate( const Dtk_dir& dir, double angle, const Dtk_pnt& center );
253  Dtk_pnt Rotated( const Dtk_dir& dir, double angle, const Dtk_pnt& center ) const;
254  void Symetry( const Dtk_dir& zpl );
255  void Symetry( const Dtk_pnt& opl, const Dtk_dir& zpl );
256  Dtk_pnt Symetrised( const Dtk_pnt& opl, const Dtk_dir& zpl ) const;
257  void Affinity( const Dtk_pnt&, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] );
258  inline void Affinity( double f[ 3 ] ) { _Coords[ 0 ] *= f[ 0 ]; _Coords[ 1 ] *= f[ 1 ]; _Coords[ 2 ] *= f[ 2 ]; }
259  Dtk_pnt Affinitised( const Dtk_pnt& p, const Dtk_dir& xdir, const Dtk_dir& ydir, double f[ 3 ] ) const;
260 };
261 
262 #endif
Dtk_pnt::x
const double & x() const
access to x coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:60
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:199
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)
config.hpp
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_pnt::Projected
Dtk_pnt Projected(const Dtk_dir &zdir, double d, const Dtk_dir &zPrj) const
Definition: dtk_pnt.hpp:236
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:711
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:63
Dtk_pnt::operator*
Dtk_pnt operator*(double a) const
Definition: dtk_pnt.hpp:143
Dtk_pnt::Project
double Project(const Dtk_pnt &org, const Dtk_dir &zdir, const Dtk_dir &zPrj)
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:698
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::Dtk_pnt
Dtk_pnt(Dtk_pnt &&s) DTK_NOEXCEPT
Dtk_pnt::Affinitised
Dtk_pnt Affinitised(const Dtk_pnt &p, const Dtk_dir &xdir, const Dtk_dir &ydir, double f[3]) const
Dtk_pnt::Projected
Dtk_pnt Projected(const Dtk_pnt &org, const Dtk_dir &zdir) const
Definition: dtk_pnt.hpp:234
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:86
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::Projected
Dtk_pnt Projected(const Dtk_dir &zdir, double d) const
Definition: dtk_pnt.hpp:238
Dtk_pnt::Affinity
void Affinity(double f[3])
Definition: dtk_pnt.hpp:258
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:70
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:240
Dtk_pnt::y
const double & y() const
access to y coordinate of the Dtk_pnt.
Definition: dtk_pnt.hpp:67
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:39
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:56
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:232
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:74
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:193
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:78
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
DTK_NOEXCEPT
#define DTK_NOEXCEPT
Definition: config.hpp:20