Code_TYMPAN  4.4.0
Industrial site acoustic simulation
3d.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef TY_MC_3D
17 #define TY_MC_3D
18 
24 #include <cmath>
25 #include <math.h>
26 #include <vector>
27 #include <ostream>
28 
29 // Defines for intersection calculations.
31 #define INTERS_CONFONDU 2
33 #define INTERS_OUI 1
35 #define INTERS_NULLE 0
36 
37 #define EPSILON_3 0.001 // 10e-3
38 #define EPSILON_5 0.00001 // 10e-5
39 #define EPSILON_6 0.000001 // 10e-6
40 #define EPSILON_7 0.0000001 // 10e-7
41 #define EPSILON_13 0.0000000000001 // 10e-13
42 #define EPSILON_50 1.e-50
43 
44 /* From this threshold (in meters), two elements are considered as at the same
45  * position
46  * */
47 #define TYSEUILCONFONDUS EPSILON_3 // 1 mm
48 
49 #ifndef M_PI
51  #define M_PI 3.1415926535897932384626433832795
52 #endif
53 
55 #define M_2PI 6.283185307179586476925287766559
56 
58 // Macros
60 
67 inline double ABS(double a)
68 {
69  return (a >= 0.0 ? a : -a);
70 }
71 
78 inline double SIGNE(double a)
79 {
80  return (a >= 0.0 ? 1 : -1);
81 }
82 
90 inline double MAX(double a, double b)
91 {
92  return (a > b ? a : b);
93 }
94 
103 inline double MAX3(double a, double b, double c)
104 {
105  return MAX(MAX(a, b), c);
106 }
107 
115 inline double MIN(double a, double b)
116 {
117  return (a < b ? a : b);
118 }
119 
126 inline double DEGTORAD(double a)
127 {
128  return (a / 180.0 * M_PI);
129 }
130 
137 inline double RADTODEG(double a)
138 {
139  return (a / M_PI * 180.0);
140 }
141 
148 inline double GRATORAD(double a)
149 {
150  return (a / 200.0 * M_PI);
151 }
152 
159 inline double RADTOGRA(double a)
160 {
161  return (a / M_PI * 200.0);
162 }
163 
170 inline double GRATODEG(double a)
171 {
172  return (a / 200.0 * 180.0);
173 }
174 
181 inline double DEGTOGRA(double a)
182 {
183  return (a / 180.0 * 200.0);
184 }
185 
192 inline int ROUND(double a)
193 {
194  return (a >= 0.0 ? (int)(a + 0.5) : (int)(a - 0.5));
195 }
196 
205 inline double BORNE(double a, double b, double c)
206 {
207  return (a < b ? b : (a > c ? c : a));
208 }
209 
216 inline int BORNE(int a)
217 {
218  return (int)BORNE((double)a, 0, 255);
219 }
220 
225 class OCoord3D
226 {
227 public:
229  OCoord3D();
231  OCoord3D(const OCoord3D& coord);
233  OCoord3D(double x, double y, double z);
235  virtual ~OCoord3D();
236 
237  OCoord3D& operator=(const OCoord3D& coord);
238  bool operator==(const OCoord3D& coord) const;
239  bool operator!=(const OCoord3D& coord) const;
240 
245  void setCoords(double x, double y, double z);
250  void setCoords(double coords[3]);
255  void getCoords(double coords[3]);
260  double* getCoords();
261 
265  operator const double*() const
266  {
267  return &_value[0];
268  }
272  operator double*()
273  {
274  return &_value[0];
275  }
276 
277 public:
278  union
279  {
280  struct
281  {
282  double _x;
283  double _y;
284  double _z;
285  };
286  double _value[3];
287  };
288 };
289 
290 ::std::ostream& operator<<(::std::ostream& os, const OCoord3D& c);
291 
297 class OVector3D : public OCoord3D
298 {
299 public:
301  OVector3D();
303  OVector3D(const OVector3D& vector);
309  OVector3D(const OCoord3D& coord);
317  OVector3D(const OCoord3D& coordFrom, const OCoord3D& coordTo);
326  OVector3D(double x, double y, double z);
328  virtual ~OVector3D();
329 
334  void reset();
336  OVector3D& operator=(const OVector3D& vector);
337  bool operator==(const OVector3D& vector) const;
338  bool operator!=(const OVector3D& vector) const;
339  OVector3D operator+(const OVector3D& vector) const;
340  OVector3D operator-(const OVector3D& vector) const;
341  // XXX meaningless component wise multiplication whereas a dot product would have been expected.
342  OVector3D operator*(const OVector3D& vector) const;
349  OVector3D operator*(const double a) const;
357  friend OVector3D operator*(const double a, const OVector3D& vector);
358 
362  double dot(const OVector3D& v)
363  {
364  return _x * v._x + _y * v._y + _z * v._z;
365  }
366 
375  OVector3D cross(const OVector3D& vector) const;
376 
385  void balance(double c1, const OVector3D& vector2, double c2);
386 
395  double scalar(const OVector3D& vector) const;
396 
403  double norme() const;
404 
411  OVector3D normal(const OVector3D& vector2, const OVector3D& vector3) const;
412 
417  void normalize();
418 
423  void invert();
424 
431  double angle(const OVector3D& vector) const;
432 
439  OVector3D getRotationOz(double alpha);
440 
447  OVector3D getRotationOzBase2(double alpha);
448 
453  OVector3D getRotationOy(double alpha);
454 
461  OVector3D getRotationOyBase2(double alpha);
462 
469  OVector3D getRotationOzOy(double alpha, double theta);
470 };
472 inline OCoord3D operator+(const OCoord3D& coord, const OVector3D& vect)
473 {
474  return OCoord3D(coord._x + vect._x, coord._y + vect._y, coord._z + vect._z);
475 }
476 
477 ::std::ostream& operator<<(::std::ostream& os, const OVector3D& v);
478 
483 class OPoint3D;
484 typedef std::vector<OPoint3D> TabPoint3D;
485 
486 class OPoint3D : public OCoord3D
487 {
488  // Methods
489 public:
493  OPoint3D();
494 
500  OPoint3D(const OPoint3D& pt);
501 
507  OPoint3D(const OCoord3D& coord);
508 
517  OPoint3D(double x, double y, double z);
518 
525  OPoint3D(double v[]);
526 
530  virtual ~OPoint3D();
531 
539  virtual void set(double x, double y, double z);
540 
548  virtual void setFromOGL(double x, double y, double z);
549  virtual void setFromOGL(float x, float y, float z);
555  virtual void setFromOGL(float coords[3]);
561  virtual void setFromOGL(double coords[3])
562  {
563  setFromOGL(coords[0], coords[1], coords[2]);
564  }
572  virtual void getToOGL(double& x, double& y, double& z);
578  virtual void getToOGL(double coords[3]);
579 
586  double distFrom(const OPoint3D& pt) const;
587 
592  double dist2DFrom(const OPoint3D& pt) const;
593 
595  bool isEqual(const OPoint3D& oPoint) const
596  {
597  return *this == oPoint;
598  }
599 
609  static TabPoint3D checkPointsMaxDistance(const TabPoint3D& points, const double& distanceMax);
610 
614  static TabPoint3D checkPointsMaxDistance(const OPoint3D& point1, const OPoint3D& point2,
615  const double& distanceMax);
616 };
617 
618 ::std::ostream& operator<<(::std::ostream& os, const OPoint3D& v);
619 
624 class OMatrix
625 {
626 public:
628  OMatrix();
630  OMatrix(const OMatrix& matrix);
631  OMatrix(double matrix[4][4]);
633  virtual ~OMatrix();
635  OMatrix& operator=(const OMatrix& matrix);
636  bool operator==(const OMatrix& matrix) const;
637  bool operator!=(const OMatrix& matrix) const;
638  OMatrix operator+(const OMatrix& matrix) const;
639  OMatrix operator-(const OMatrix& matrix) const;
640  OMatrix operator*(const OMatrix& matrix) const;
641 
648  OVector3D multNormal(const OVector3D& normal) const;
649 
654  void show();
655 
665  void reset();
666 
676  void unite();
677 
689  int setTranslation(double x, double y, double z);
690 
702  int setScale(double x, double y, double z);
703 
713  int setRotationOx(double a);
714 
724  int setRotationOy(double a);
725 
735  int setRotationOz(double a);
736 
778  int aligneVecteurSurOx(const OVector3D& vector);
779 
821  int aligneVecteurSurOy(const OVector3D& vector);
822 
839  int invert();
840 
849  OMatrix getInvert(int* ok = 0) const;
850 
875  void adjoint();
876 
884 
892  double determinant();
893 
898  static double mat2x2Det(double a, double b, double c, double d);
899 
904  static double mat3x3Det(double a1, double a2, double a3, double b1, double b2, double b3, double c1,
905  double c2, double c3);
906 
913  OCoord3D dot(const OCoord3D& coord) const;
914 
917  OCoord3D scale(const OCoord3D& coord) const;
918 
919  // Conversion from/to OpenGL column-major matrix format
920 
927  static inline OMatrix fromOpenGL(double mat[16])
928  {
929  double rowMajor[4][4] = {
930  {mat[0], mat[4], mat[8], mat[12]},
931  {mat[1], mat[5], mat[9], mat[13]},
932  {mat[2], mat[6], mat[10], mat[14]},
933  {mat[3], mat[7], mat[11], mat[15]},
934  };
935  return OMatrix{rowMajor};
936  }
937 
944  inline void toOpenGL(double mat[16])
945  {
946  // first column
947  mat[0] = _m[0][0];
948  mat[1] = _m[1][0];
949  mat[2] = _m[2][0];
950  mat[3] = _m[3][0];
951 
952  // second column
953  mat[4] = _m[0][1];
954  mat[5] = _m[1][1];
955  mat[6] = _m[2][1];
956  mat[7] = _m[3][1];
957 
958  // third column
959  mat[8] = _m[0][2];
960  mat[9] = _m[1][2];
961  mat[10] = _m[2][2];
962  mat[11] = _m[3][2];
963 
964  // fourth column
965  mat[12] = _m[0][3];
966  mat[13] = _m[1][3];
967  mat[14] = _m[2][3];
968  mat[15] = _m[3][3];
969  }
970 
971  // Members
972 public:
974  double _m[4][4];
975 };
976 
977 OVector3D operator*(const OMatrix& mat, const OVector3D& vec);
978 OPoint3D operator*(const OMatrix& mat, const OPoint3D& pt);
979 
985 {
986 public:
998  static bool intersDemiSegmentAvecSegment(const OPoint3D& ptS, const OPoint3D& ptA, const OPoint3D& ptB);
999 
1013  static int intersDroitesPoints(const OPoint3D& ptA, const OPoint3D& ptB, const OPoint3D& ptC,
1014  const OPoint3D& ptD, OPoint3D& ptI);
1015 
1029  static int intersDroitesPointVecteur(const OPoint3D& ptA, const OVector3D& vecA, const OPoint3D& ptB,
1030  const OVector3D& vecB, OPoint3D& ptI);
1031 
1044  static double symPointDroite(const OPoint3D& ptA, const OPoint3D& ptB, const OPoint3D& ptP,
1045  OPoint3D& ptI);
1046 
1071  static bool pointInPolygonAngleSum(const OPoint3D& ptP, const OPoint3D* pts, int nbPts);
1072 
1084  static bool pointInPolygonRayCasting(const OPoint3D& ptP, const OPoint3D* pts, int nbPts);
1085 
1110  static bool shortestSegBetween2Lines(const OPoint3D& pt1, const OPoint3D& pt2, const OPoint3D& pt3,
1111  const OPoint3D& pt4, OPoint3D& ptA, OPoint3D& ptB, double* mua,
1112  double* mub);
1113 
1123  static void boundingBox(OPoint3D* pts, int nbPts, OPoint3D& ptMin, OPoint3D& ptMax);
1124 
1133  static void computeNormal(OPoint3D* pts, int nbPts, OVector3D& normal);
1134 };
1135 
1141 {
1142 public:
1144  OSegment3D();
1146  OSegment3D(const OSegment3D& other);
1147  OSegment3D(const OPoint3D& ptA, const OPoint3D& ptB);
1149  virtual ~OSegment3D();
1150 
1151  virtual OSegment3D& operator=(const OSegment3D& other);
1152  virtual bool operator==(const OSegment3D& other) const;
1153  virtual bool operator!=(const OSegment3D& other) const;
1154 
1163  virtual OSegment3D operator*(const OMatrix& matrix) const;
1164 
1169  virtual double longueur() const;
1170 
1180  virtual int symetrieOf(const OPoint3D& pt, OPoint3D& ptSym) const;
1181 
1193  virtual int projection(const OPoint3D& pt, OPoint3D& ptProj, double seuilConfondus) const;
1194 
1208  virtual int intersects(const OSegment3D& seg, OPoint3D& pt, double seuilConfondus) const;
1209 
1216  virtual OPoint3D centreOf() const;
1217 
1224  virtual OPoint3D centerOfCurvedPath(const double& R) const;
1225 
1232  virtual double lengthOfCurvedPath(const double& R);
1233 
1240  virtual OVector3D toVector3D() const
1241  {
1242  return OVector3D(_ptA, _ptB);
1243  }
1244 
1249  virtual OSegment3D swap() const;
1250 
1251 public:
1256 };
1257 
1263 {
1264 public:
1266  ORepere3D();
1268  ORepere3D(const ORepere3D& repere);
1277  ORepere3D(const OPoint3D& origin, const OVector3D& vecI, const OVector3D& vecJ, const OVector3D& vecK);
1282  ORepere3D(const OPoint3D& origin, const OVector3D& vec);
1288  ORepere3D(const OMatrix& matrix);
1290  virtual ~ORepere3D();
1291 
1292  ORepere3D& operator=(const ORepere3D& repere);
1293  bool operator==(const ORepere3D& repere) const;
1294  bool operator!=(const ORepere3D& repere) const;
1295 
1305  void set(const OPoint3D& origin, const OVector3D& vecI, const OVector3D& vecJ, const OVector3D& vecK);
1306 
1313  void set(const OMatrix& matrix);
1314 
1319  void normalize();
1320 
1327  OMatrix asMatrix() const;
1328 
1329 public:
1338 };
1339 
1345 class OBox
1346 {
1347 public:
1349  OBox();
1351  OBox(const OBox& box);
1352  OBox(const OCoord3D& min, const OCoord3D& max);
1353  OBox(double x1, double y1, double z1, double x2, double y2, double z2);
1355  virtual ~OBox() {}
1356 
1357  virtual OBox& operator=(const OBox& box);
1358  virtual bool operator==(const OBox& box) const;
1359  virtual bool operator!=(const OBox& box) const
1360  {
1361  return !operator==(box);
1362  }
1363 
1370  virtual bool isInside(const OPoint3D& pt) const;
1371 
1378  virtual bool isInside2D(const OPoint3D& pt) const;
1379 
1386  virtual bool isInContact(const OBox& box) const;
1387 
1394  virtual void Enlarge(const OPoint3D& pt);
1395 
1404  virtual void Enlarge(float x, float y, float z);
1405 
1412  virtual void Enlarge(const OBox& box);
1413 
1420  virtual void Translate(const OPoint3D& vectorTranslate);
1421 
1422 public:
1425 };
1426 
1431 class OBox2 : public OBox
1432 {
1433  // Methods
1434 public:
1436  OBox2();
1438  OBox2(const OBox2& box);
1444  OBox2(const OBox& box);
1449  OBox2(const double& length, const double& width, const double& height);
1450 
1451 private: // Set private for security seems to an "af hoc" adaptation and is used only by an internal member
1452  // function
1460  OBox2(const OBox2& box, const ORepere3D& repere, const OPoint3D& centre);
1461 
1462 public:
1464  virtual ~OBox2() {}
1465 
1466  virtual OBox2& operator=(const OBox2& box);
1467  virtual bool operator==(const OBox2& box) const;
1468  virtual bool operator!=(const OBox2& box) const
1469  {
1470  return !operator==(box);
1471  }
1472 
1482  OPoint3D BoxCoord(int N) const;
1488  virtual bool isInside(const OPoint3D& pt) const;
1494  virtual bool isInside2D(const OPoint3D& pt) const;
1499  virtual void Translate(const OVector3D& vect);
1503  OBox2 boxRotation(const OPoint3D& O, const OPoint3D& P2);
1510  void BoxRotationOzOy(double alpha, double theta);
1515  void moveAndRotate(const OPoint3D& origin, const OVector3D& vec);
1516 
1517 private:
1522  OBox2 rotInXOYOnly(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1527  OBox2 rotInXOZOnly(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1532  OBox2 rot3D(const OVector3D& v1, const OVector3D& v2, const OPoint3D& O, const OPoint3D& P2);
1533 
1534 public:
1545  double _length;
1546  double _height;
1547  double _width;
1548 };
1549 
1566 {
1567 public:
1569  OHPlane3D();
1571  OHPlane3D(const OHPlane3D& Plane);
1578  OHPlane3D(const OVector3D& normal, const OPoint3D& origin);
1580  virtual ~OHPlane3D();
1581 
1588  void set(const OVector3D& normal, const OPoint3D& origin);
1589 
1590  OHPlane3D& operator=(const OHPlane3D& Plane);
1591  bool operator==(const OHPlane3D& Plane) const;
1592  bool operator!=(const OHPlane3D& Plane) const;
1593 
1612  int intersects(const OPoint3D& pt1, const OPoint3D& pt2, OPoint3D& ptIntersec, double& t) const;
1629  int intersects(const OSegment3D& seg, OPoint3D& ptIntersec) const;
1630 
1631 private:
1634  double _p;
1635 };
1636 
1637 #endif // TY_MC_3D
double RADTODEG(double a)
Converts an angle from radians to degrees.
Definition: 3d.h:137
double MAX3(double a, double b, double c)
Return the biggest number of three ones.
Definition: 3d.h:103
double MIN(double a, double b)
Return the smallest number of two ones.
Definition: 3d.h:115
double BORNE(double a, double b, double c)
Limit a number.
Definition: 3d.h:205
double GRATORAD(double a)
Converts an angle from gradians to radians.
Definition: 3d.h:148
::std::ostream & operator<<(::std::ostream &os, const OCoord3D &c)
Definition: 3d.cpp:106
OCoord3D operator+(const OCoord3D &coord, const OVector3D &vect)
Return a OCoord3D from an operator+ between a OCoord3D and a OVector3D.
Definition: 3d.h:472
double GRATODEG(double a)
Converts an angle from gradians to degrees.
Definition: 3d.h:170
OVector3D operator*(const OMatrix &mat, const OVector3D &vec)
Definition: 3d.cpp:568
double DEGTORAD(double a)
Converts an angle from degrees to radians.
Definition: 3d.h:126
double DEGTOGRA(double a)
Converts an angle from degrees to gradians.
Definition: 3d.h:181
int ROUND(double a)
Compute the rounded value of a number.
Definition: 3d.h:192
double RADTOGRA(double a)
Converts an angle from radians to gradians.
Definition: 3d.h:159
#define M_PI
Pi.
Definition: 3d.h:51
double SIGNE(double a)
Return the number sign.
Definition: 3d.h:78
double ABS(double a)
Return the absolute value.
Definition: 3d.h:67
double MAX(double a, double b)
Return the biggest number of two ones.
Definition: 3d.h:90
std::vector< OPoint3D > TabPoint3D
Definition: 3d.h:483
NxReal c
Definition: NxVec3.cpp:317
#define min(a, b)
Class to define a box (not necessary parallel to the axis as OBox)
Definition: 3d.h:1432
virtual bool operator==(const OBox2 &box) const
Definition: 3d.cpp:1791
OPoint3D _H
Definition: 3d.h:1544
ORepere3D _repere
Definition: 3d.h:1535
double _width
Definition: 3d.h:1547
OPoint3D _D
Definition: 3d.h:1540
virtual bool isInside(const OPoint3D &pt) const
Test whether the point is inside the box or not.
Definition: 3d.cpp:1887
OBox2 rotInXOZOnly(const OVector3D &v1, const OVector3D &v2, const OPoint3D &O, const OPoint3D &P2)
Definition: 3d.cpp:2028
OPoint3D _E
Definition: 3d.h:1541
double _length
Definition: 3d.h:1545
virtual ~OBox2()
Destructor.
Definition: 3d.h:1464
OBox2()
Default constructor.
Definition: 3d.cpp:1700
OPoint3D _center
Definition: 3d.h:1536
virtual bool isInside2D(const OPoint3D &pt) const
Test whether the point is inside the box or not (from upper point of view).
Definition: 3d.cpp:1900
OPoint3D BoxCoord(int N) const
Returns the coordinates of one of the box corner. \ We consider that the first corner is the one on t...
Definition: 3d.cpp:1859
double _height
Definition: 3d.h:1546
virtual bool operator!=(const OBox2 &box) const
Definition: 3d.h:1468
OPoint3D _C
Definition: 3d.h:1539
OBox2 boxRotation(const OPoint3D &O, const OPoint3D &P2)
Definition: 3d.cpp:1927
OPoint3D _G
Definition: 3d.h:1543
OPoint3D _F
Definition: 3d.h:1542
OBox2 rot3D(const OVector3D &v1, const OVector3D &v2, const OPoint3D &O, const OPoint3D &P2)
Definition: 3d.cpp:2050
virtual OBox2 & operator=(const OBox2 &box)
Definition: 3d.cpp:1769
virtual void Translate(const OVector3D &vect)
Translate this box.
Definition: 3d.cpp:1914
void moveAndRotate(const OPoint3D &origin, const OVector3D &vec)
Move and rotate the box.
Definition: 3d.cpp:2090
OBox2 rotInXOYOnly(const OVector3D &v1, const OVector3D &v2, const OPoint3D &O, const OPoint3D &P2)
Definition: 3d.cpp:2009
OPoint3D _B
Definition: 3d.h:1538
void BoxRotationOzOy(double alpha, double theta)
Computes the box rotation around Oz and Oy (usual coordinates system).
Definition: 3d.cpp:1976
OPoint3D _A
Definition: 3d.h:1537
The box class.
Definition: 3d.h:1346
virtual bool isInContact(const OBox &box) const
Test whether the boxes are in contact or not.
Definition: 3d.cpp:1585
virtual bool isInside2D(const OPoint3D &pt) const
Test whether the point is inside the box or not (from upper point of view).
Definition: 3d.cpp:1564
virtual ~OBox()
Destructor.
Definition: 3d.h:1355
virtual bool isInside(const OPoint3D &pt) const
Test whether the point is inside the box or not.
Definition: 3d.cpp:1535
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
Definition: 3d.cpp:1614
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1423
virtual bool operator==(const OBox &box) const
Definition: 3d.cpp:1519
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1424
virtual bool operator!=(const OBox &box) const
Definition: 3d.h:1359
virtual void Translate(const OPoint3D &vectorTranslate)
Translate this box.
Definition: 3d.cpp:1688
OBox()
Default constructor.
Definition: 3d.cpp:1486
virtual OBox & operator=(const OBox &box)
Definition: 3d.cpp:1509
The 3D coordinate class.
Definition: 3d.h:226
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
OCoord3D & operator=(const OCoord3D &coord)
operator=
Definition: 3d.cpp:40
OCoord3D()
Default constructor.
Definition: 3d.cpp:29
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
bool operator==(const OCoord3D &coord) const
operator==
Definition: 3d.cpp:51
void setCoords(double x, double y, double z)
Sets the coordinates as an array of double.
Definition: 3d.cpp:76
bool operator!=(const OCoord3D &coord) const
operator!=
Definition: 3d.cpp:71
double _value[3]
Definition: 3d.h:286
double * getCoords()
Gets the coordinates as an array of double.
Definition: 3d.cpp:97
virtual ~OCoord3D()
Destructor.
Definition: 3d.cpp:38
Class Geometry utilities.
Definition: 3d.h:985
static void boundingBox(OPoint3D *pts, int nbPts, OPoint3D &ptMin, OPoint3D &ptMax)
Computes the simple bounding box for a volume using min-max method.
Definition: 3d.cpp:1109
static bool intersDemiSegmentAvecSegment(const OPoint3D &ptS, const OPoint3D &ptA, const OPoint3D &ptB)
Return true if the horizontal from the ptS point intersects the segment defined by ptA and ptB.
Definition: 3d.cpp:915
static void computeNormal(OPoint3D *pts, int nbPts, OVector3D &normal)
Computes the normal of the list of points.
Definition: 3d.cpp:1147
static bool shortestSegBetween2Lines(const OPoint3D &pt1, const OPoint3D &pt2, const OPoint3D &pt3, const OPoint3D &pt4, OPoint3D &ptA, OPoint3D &ptB, double *mua, double *mub)
Calculates the line segment PaPb that is the shortest route between two lines P1P2 and P3P4.
Definition: 3d.cpp:1063
static double symPointDroite(const OPoint3D &ptA, const OPoint3D &ptB, const OPoint3D &ptP, OPoint3D &ptI)
Calculate the symmetrical of a point with respect to a line (defined by two points).
Definition: 3d.cpp:987
static bool pointInPolygonAngleSum(const OPoint3D &ptP, const OPoint3D *pts, int nbPts)
Tests if a point is inside a polygon using angle sum algorithm.
Definition: 3d.cpp:1016
static bool pointInPolygonRayCasting(const OPoint3D &ptP, const OPoint3D *pts, int nbPts)
Tests if a point is inside a polygon using ray casting algorithm.
Definition: 3d.cpp:1046
static int intersDroitesPointVecteur(const OPoint3D &ptA, const OVector3D &vecA, const OPoint3D &ptB, const OVector3D &vecB, OPoint3D &ptI)
Calculate the intersection between two lines each defined by a point and a vector.
Definition: 3d.cpp:977
static int intersDroitesPoints(const OPoint3D &ptA, const OPoint3D &ptB, const OPoint3D &ptC, const OPoint3D &ptD, OPoint3D &ptI)
Calculate the intersection between two lines each defined by two points.
Definition: 3d.cpp:938
The 3D Plane class using Hessian normal form.
Definition: 3d.h:1566
bool operator!=(const OHPlane3D &Plane) const
Definition: 3d.cpp:2148
bool operator==(const OHPlane3D &Plane) const
Definition: 3d.cpp:2140
double _p
Definition: 3d.h:1634
int intersects(const OPoint3D &pt1, const OPoint3D &pt2, OPoint3D &ptIntersec, double &t) const
Calculate the intersection with a segment defined by two points.
Definition: 3d.cpp:2167
OHPlane3D & operator=(const OHPlane3D &Plane)
Definition: 3d.cpp:2132
virtual ~OHPlane3D()
Destructor.
Definition: 3d.cpp:2123
void set(const OVector3D &normal, const OPoint3D &origin)
set a new Plane.
Definition: 3d.cpp:2125
OVector3D _N
Definition: 3d.h:1632
OHPlane3D()
Default constructor.
Definition: 3d.cpp:2107
OPoint3D _O
Definition: 3d.h:1633
The 4x4 matrix class.
Definition: 3d.h:625
virtual ~OMatrix()
Destructor.
Definition: 3d.cpp:461
OCoord3D scale(const OCoord3D &coord) const
Definition: 3d.cpp:554
static double mat3x3Det(double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
Compute a 3 x 3 matrix determinant.
Definition: 3d.cpp:906
int setRotationOz(double a)
Update a rotation matrix (Oz axis).
Definition: 3d.cpp:688
int setRotationOy(double a)
Update a rotation matrix (Oy axis).
Definition: 3d.cpp:676
int invert()
Matrix inversion.
Definition: 3d.cpp:792
void reset()
Set the matrix elements to zero.
Definition: 3d.cpp:622
OMatrix getInvert(int *ok=0) const
Return the inverse matrix of this matrix.
Definition: 3d.cpp:813
static double mat2x2Det(double a, double b, double c, double d)
Compute a 2 x 2 matrix determinant.
Definition: 3d.cpp:901
void toOpenGL(double mat[16])
Store content of this matrix in column-major format at mat.
Definition: 3d.h:944
void unite()
Initialize the matrix to the identity matrix.
Definition: 3d.cpp:634
OMatrix operator*(const OMatrix &matrix) const
Definition: 3d.cpp:527
OVector3D multNormal(const OVector3D &normal) const
Multiplication with a normal (the translation is removed).
Definition: 3d.cpp:585
int aligneVecteurSurOx(const OVector3D &vector)
Mise a jour d'une matrice d'alignement d'un vecteur quelconque avec l'axe des x.
Definition: 3d.cpp:700
OMatrix & operator=(const OMatrix &matrix)
operators
Definition: 3d.cpp:463
OMatrix operator-(const OMatrix &matrix) const
Definition: 3d.cpp:514
OMatrix()
Default constructor.
Definition: 3d.cpp:439
int setRotationOx(double a)
Update a rotation matrix (Ox axis).
Definition: 3d.cpp:664
bool operator==(const OMatrix &matrix) const
Definition: 3d.cpp:478
OMatrix operator+(const OMatrix &matrix) const
Definition: 3d.cpp:501
void adjoint()
Calculate the adjoint matrix from this matrix.
Definition: 3d.cpp:824
bool operator!=(const OMatrix &matrix) const
Definition: 3d.cpp:496
void show()
Print a matrix (debug).
Definition: 3d.cpp:609
int setTranslation(double x, double y, double z)
Update a translation matrix.
Definition: 3d.cpp:646
OMatrix getAdjoint()
Return the adjoint matrix.
Definition: 3d.cpp:865
double determinant()
Compute the matrix determinant.
Definition: 3d.cpp:873
int aligneVecteurSurOy(const OVector3D &vector)
Mise a jour d'une matrice d'alignement d'un vecteur quelconque avec l'axe des y.
Definition: 3d.cpp:743
OCoord3D dot(const OCoord3D &coord) const
Multiplication with a 3D coordinate.
Definition: 3d.cpp:545
int setScale(double x, double y, double z)
Update a zoom matrix.
Definition: 3d.cpp:655
static OMatrix fromOpenGL(double mat[16])
Construct an OMatrix from a matrix obtained from a glGetDoublev(PROJECTION_MATRIX,...
Definition: 3d.h:927
double _m[4][4]
The 4x4 matrix array.
Definition: 3d.h:974
The 3D point class.
Definition: 3d.h:487
virtual ~OPoint3D()
Destructor.
Definition: 3d.cpp:338
virtual void set(double x, double y, double z)
Definition: 3d.cpp:381
double dist2DFrom(const OPoint3D &pt) const
Computes the distance from this point to another in 2D plan.
Definition: 3d.cpp:376
double distFrom(const OPoint3D &pt) const
Computes the distance from this point to another.
Definition: 3d.cpp:371
OPoint3D()
Default constructor.
Definition: 3d.cpp:328
virtual void getToOGL(double &x, double &y, double &z)
Definition: 3d.cpp:359
bool isEqual(const OPoint3D &oPoint) const
Compatibility alias for operator==.
Definition: 3d.h:595
virtual void setFromOGL(double x, double y, double z)
Definition: 3d.cpp:340
virtual void setFromOGL(double coords[3])
Definition: 3d.h:561
static TabPoint3D checkPointsMaxDistance(const TabPoint3D &points, const double &distanceMax)
Definition: 3d.cpp:386
3D frame with a point and 3 vectors.
Definition: 3d.h:1263
void normalize()
Normalize each vectors composing this frame.
Definition: 3d.cpp:1455
OVector3D _vecK
Vector K for the Z axis.
Definition: 3d.h:1337
bool operator==(const ORepere3D &repere) const
operator==
Definition: 3d.cpp:1398
OVector3D _vecJ
Vector J for the Y axis.
Definition: 3d.h:1335
ORepere3D & operator=(const ORepere3D &repere)
operator=
Definition: 3d.cpp:1386
void set(const OPoint3D &origin, const OVector3D &vecI, const OVector3D &vecJ, const OVector3D &vecK)
Sets with a point and 3 vectors.
Definition: 3d.cpp:1427
OVector3D _vecI
Vector I for the X axis.
Definition: 3d.h:1333
OPoint3D _origin
The origin point.
Definition: 3d.h:1331
ORepere3D()
Default constructor.
Definition: 3d.cpp:1347
OMatrix asMatrix() const
return the transformation matrix from unity to this pose such as this = transform * unity
Definition: 3d.cpp:1462
bool operator!=(const ORepere3D &repere) const
operator!=
Definition: 3d.cpp:1422
virtual ~ORepere3D()
Destructor.
Definition: 3d.cpp:1384
Class to define a segment.
Definition: 3d.h:1141
virtual double longueur() const
Return the segment length.
Definition: 3d.cpp:1238
virtual OPoint3D centreOf() const
Return the position of the segment middle.
Definition: 3d.cpp:1294
virtual ~OSegment3D()
Destructor.
Definition: 3d.cpp:1200
virtual OPoint3D centerOfCurvedPath(const double &R) const
Return the position of the arc circle center of radius R passing by the segment extremities.
Definition: 3d.cpp:1303
OSegment3D()
Default constructor.
Definition: 3d.cpp:1179
virtual int symetrieOf(const OPoint3D &pt, OPoint3D &ptSym) const
Return the symmetrical of a point.
Definition: 3d.cpp:1243
virtual double lengthOfCurvedPath(const double &R)
Calculate the path length of radius R passing by the segment extremities.
Definition: 3d.cpp:1327
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1253
virtual OVector3D toVector3D() const
Build a OVector3D from a segment used for the direction of the sources.
Definition: 3d.h:1240
virtual bool operator!=(const OSegment3D &other) const
operator!=
Definition: 3d.cpp:1228
virtual int projection(const OPoint3D &pt, OPoint3D &ptProj, double seuilConfondus) const
Return the projection of a point.
Definition: 3d.cpp:1258
virtual int intersects(const OSegment3D &seg, OPoint3D &pt, double seuilConfondus) const
Return the intersection point with another segment.
Definition: 3d.cpp:1267
virtual OSegment3D swap() const
Return the segment.
Definition: 3d.cpp:1336
virtual OSegment3D operator*(const OMatrix &matrix) const
Multiplication with a matrix.
Definition: 3d.cpp:1233
virtual bool operator==(const OSegment3D &other) const
operator==
Definition: 3d.cpp:1212
virtual OSegment3D & operator=(const OSegment3D &other)
operator=
Definition: 3d.cpp:1202
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1255
The 3D vector class.
Definition: 3d.h:298
OVector3D operator*(const OVector3D &vector) const
Definition: 3d.cpp:171
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
OVector3D getRotationOzBase2(double alpha)
Returns the vector after a rotation around z axis \ and gives back the coordinates of xprime or yprim...
Definition: 3d.cpp:280
void invert()
Inverts this vector.
Definition: 3d.cpp:236
OVector3D normal(const OVector3D &vector2, const OVector3D &vector3) const
Computes the normal with this vector and 2 others.
Definition: 3d.cpp:220
void balance(double c1, const OVector3D &vector2, double c2)
Balances this vector.
Definition: 3d.cpp:205
virtual ~OVector3D()
Destructor.
Definition: 3d.cpp:128
OVector3D operator-(const OVector3D &vector) const
Definition: 3d.cpp:162
OVector3D getRotationOzOy(double alpha, double theta)
Returns the vector after 2 rotations around z axis and y axis. It gives the coordinates of xsecond,...
Definition: 3d.cpp:306
bool operator!=(const OVector3D &vector) const
Definition: 3d.cpp:148
bool operator==(const OVector3D &vector) const
Definition: 3d.cpp:143
void normalize()
Normalizes this vector.
Definition: 3d.cpp:225
double scalar(const OVector3D &vector) const
Performs the scalar product between this object and another vector.
Definition: 3d.cpp:210
OVector3D cross(const OVector3D &vector) const
Cross product.
Definition: 3d.cpp:196
double angle(const OVector3D &vector) const
Computes the angle between this vector and another vector.
Definition: 3d.cpp:243
OVector3D()
Default constructor.
Definition: 3d.cpp:113
OVector3D operator+(const OVector3D &vector) const
Definition: 3d.cpp:153
OVector3D getRotationOz(double alpha)
Returns the vector after a rotation around z axis \ x -> xprime. Both of these vectors will be given ...
Definition: 3d.cpp:254
OVector3D & operator=(const OVector3D &vector)
operators
Definition: 3d.cpp:137
OVector3D getRotationOyBase2(double alpha)
Returns the vector after a rotation around y axis \ and gives back the coordinates of xprime or zprim...
Definition: 3d.cpp:293
OVector3D getRotationOy(double alpha)
Returns the vector after a rotation around z axis.
Definition: 3d.cpp:267
double dot(const OVector3D &v)
dot product (assuming an orthonormal reference frame)
Definition: 3d.h:362
void reset()
Reset this vector.
Definition: 3d.cpp:130