xc
Segment3d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Segment3d.h
22 
23 #ifndef SEGMENT3D_H
24 #define SEGMENT3D_H
25 
26 #include "Linear3d.h"
27 #include "Line3d.h"
28 #include "Ray3d.h"
29 #include "../pos_vec/Pos3d.h"
30 
31 class Dir3d;
32 class VectorPos3d;
33 class Polyline3d;
34 class Plane;
35 
36 typedef std::pair<int,int> int_pair;
37 typedef std::deque<int_pair> int_pair_deque;
38 
40 //
42 class Segment3d : public Linear3d
43  {
44  CGSegment_3 cgseg;
45  public:
46  Segment3d(void);
47  Segment3d(const CGSegment_3 &r);
48  Segment3d(const Pos3d &p1,const Pos3d &p2);
49  virtual bool operator==(const Segment3d &) const;
50 
51  const CGSegment_3 &ToCGAL(void) const
52  { return cgseg; }
53  virtual GeomObj *getCopy(void) const;
54  void swap(void);
55  void TwoPoints(const Pos3d &p1,const Pos3d &p2);
56  virtual GEOM_FT GetMax(unsigned short int i) const;
57  virtual GEOM_FT GetMin(unsigned short int i) const;
58  Line3d getSupportLine(void) const;
59  Pos3d getFromPoint(void) const;
60  Pos3d getToPoint(void) const;
61  GEOM_FT getSlope(void) const;
62  bool upwards(void) const;
63  bool downwards(void) const;
64  const Pos3d Point(const int &i) const;
65  Pos3d PtoParametricas(const GEOM_FT &lambda) const;
66  Pos3d getMidPoint(void) const;
67  double getParamNaturalCoord(const GEOM_FT &) const;
68  Pos3d getPointNaturalCoord(const GEOM_FT &chi) const;
69  GEOM_FT getLambda(const Pos3d &p) const;
70  bool isDegenerated(void) const;
71  virtual bool In(const Pos3d &p, const double &tol= 0.0) const;
72  virtual GEOM_FT dist2(const Pos3d &p) const;
73  GEOM_FT dist(const Pos3d &p) const;
74  void Put(const Pos3d &p1,const Pos3d &p2);
75 
76  bool isParallel(const Line3d &r) const;
77  bool isParallel(const Ray3d &sr) const;
78  bool isParallel(const Segment3d &r) const;
79 
80  GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const;
84  bool connected(const Pos3d &, const GEOM_FT &tol= 0.0) const;
85 
86  Pos3d Projection(const Pos3d &) const;
87  Vector3d Projection(const Vector3d &) const;
88 
89  virtual GEOM_FT getLength(void) const;
90  virtual Pos3d getCenterOfMass(void) const;
91  Dir3d GetDir(void) const;
92  Vector3d VDir(void) const;
93  virtual Vector3d getIVector(void) const;
94  virtual Vector3d getJVector(void) const;
95  virtual Vector3d getKVector(void) const;
96  GEOM_FT getAngle(const Vector3d &) const;
97  GEOM_FT getAngle(const Line3d &) const;
98  GEOM_FT getAngle(const Ray3d &) const;
99  GEOM_FT getAngle(const Segment3d &) const;
100  GEOM_FT getAngle(const Plane &) const;
101  GEOM_FT getAngleXYPlane(void) const;
102  GEOM_FT getAngleXZPlane(void) const;
103  GEOM_FT getAngleYZPlane(void) const;
104  friend GEOM_FT angle(const Segment3d &r,const Vector3d &v);
105  virtual GEOM_FT Ix(void) const;
106  virtual GEOM_FT Iy(void) const;
107  virtual GEOM_FT Iz(void) const;
108 
109  VectorPos3d Divide(int num_partes) const;
110  boost::python::list DividePy(int num_partes) const;
111  VectorPos3d Divide(const std::vector<double> &) const;
112  boost::python::list DividePy(const boost::python::list &) const;
113  boost::python::list split(const Pos3d &) const;
114 
115  boost::python::dict getPyDict(void) const;
116  void setPyDict(const boost::python::dict &);
117 
118  void Print(std::ostream &os) const;
119  };
120 
121 inline GEOM_FT dist2(const Pos3d &p,const Segment3d &r)
122  { return r.dist2(p); }
123 inline GEOM_FT dist2(const Segment3d &r,const Pos3d &p)
124  { return dist2(p,r); }
125 GEOM_FT dist(const Pos3d &p,const Segment3d &r);
126 inline GEOM_FT dist(const Segment3d &r,const Pos3d &p)
127  { return dist(p,r); }
128 
129 inline bool parallel(const Segment3d &sg,const Line3d &r)
130  { return sg.isParallel(r); }
131 inline bool parallel(const Line3d &r, const Segment3d &sg)
132  { return parallel(sg,r); }
133 inline bool parallel(const Segment3d &sg,const Ray3d &sr)
134  { return sg.isParallel(sr); }
135 inline bool parallel(const Ray3d &sr, const Segment3d &sg)
136  { return parallel(sg,sr); }
137 inline bool parallel(const Segment3d &r1,const Segment3d &r2)
138  { return r1.isParallel(r2); }
139 
140 inline bool colineales(const Segment3d &sg,const Line3d &r)
141  { return colineales(sg.getSupportLine(),r); }
142 inline bool colineales(const Line3d &r,const Segment3d &sg)
143  { return colineales(sg,r); }
144 inline bool colineales(const Segment3d &sg,const Ray3d &sr)
145  { return colineales(sg.getSupportLine(),sr); }
146 inline bool colineales(const Ray3d &sr,const Segment3d &sg)
147  { return colineales(sg,sr); }
148 inline bool colineales(const Segment3d &sg1,const Segment3d &sg2)
149  { return colineales(sg1,sg2.getSupportLine()); }
150 
151 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg,const Line3d &r)
152  { return sg.getIntersection(r); }
153 inline GeomObj3d::list_Pos3d intersection(const Line3d &r, const Segment3d &sg)
154  { return sg.getIntersection(r); }
155 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg,const Ray3d &sr)
156  { return sg.getIntersection(sr); }
157 inline GeomObj3d::list_Pos3d intersection(const Ray3d &sr, const Segment3d &sg)
158  { return sg.getIntersection(sr); }
159 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg1,const Segment3d &sg2)
160  { return sg1.getIntersection(sg2); }
161 
162 int_pair_deque getIntersections(const std::deque<Segment3d> &);
163 
164 std::list<Polyline3d> get_polylines(const std::list<Segment3d> &, const GEOM_FT &tol);
165 boost::python::list py_get_3d_polylines(const boost::python::list &, const GEOM_FT &tol);
166 
167 #endif
Pos3d getPointNaturalCoord(const GEOM_FT &chi) const
Return the parametric coordinate that corresponds to the natural coordinate being passed as parameter...
Definition: Segment3d.cc:121
Pos3d Projection(const Pos3d &) const
Return the orthogonal projection onto the line.
Definition: Segment3d.cc:328
virtual GEOM_FT dist2(const Pos3d &p) const
Return the squared distance from the point to the segment.
Definition: Segment3d.cc:168
bool upwards(void) const
Return true if the segment goes up.
Definition: Segment3d.cc:96
virtual Vector3d getJVector(void) const
Returns a vector in the direction of the local Y axis.
Definition: Segment3d.cc:150
Segment en tres dimensiones.
Definition: Segment3d.h:42
virtual GeomObj * getCopy(void) const
Virtual constructor.
Definition: Segment3d.cc:73
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Segment3d.cc:82
virtual GEOM_FT getLength(void) const
Return the length of the segment.
Definition: Segment3d.cc:199
Polyline in a three-dimensional space.
Definition: Polyline3d.h:37
bool connected(const Pos3d &, const GEOM_FT &tol=0.0) const
Return true if the segment is connected to the argument point (i.
Definition: Segment3d.cc:313
GEOM_FT getAngle(const Vector3d &) const
Returns the angle with the vector argument.
Definition: Segment3d.cc:347
Plane in a three-dimensional space.
Definition: Plane.h:49
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Segment3d.cc:489
void swap(void)
@ brief Swaps the segment orientation.
Definition: Segment3d.cc:77
boost::python::list DividePy(int num_partes) const
Return a Python list containing the points that results from the segment division.
Definition: Segment3d.cc:409
Pos3d getMidPoint(void) const
Return the mid point of the segment.
Definition: Segment3d.cc:111
Ray in a three-dimensional space.
Definition: Ray3d.h:36
Base class for the objects involving a single dimension in a three-dimensional space.
Definition: Linear3d.h:33
GEOM_FT getAngleXYPlane(void) const
Returns angle with the XY plane.
Definition: Segment3d.cc:367
virtual bool In(const Pos3d &p, const double &tol=0.0) const
Return true if the point is in the segment.
Definition: Segment3d.cc:127
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Segment3d.cc:498
GEOM_FT getSlope(void) const
Return the angle or the line with respect to XY plane.
Definition: Segment3d.cc:92
virtual Vector3d getIVector(void) const
Returns a vector in the direction of the local X axis.
Definition: Segment3d.cc:145
boost::python::list split(const Pos3d &) const
Return the two segments that result from splitting this one on the point nearest to the argument...
Definition: Segment3d.cc:468
virtual GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: Segment3d.cc:80
Dirección en el espacio de tres dimensiones.
Definition: Dir3d.h:35
Segment3d(void)
Constructor.
Definition: Segment3d.cc:39
GEOM_FT getAngleXZPlane(void) const
Returns angle with the XZ plane.
Definition: Segment3d.cc:373
void Put(const Pos3d &p1, const Pos3d &p2)
Set the extremities of the segment.
Definition: Segment3d.cc:140
Pos3d PtoParametricas(const GEOM_FT &lambda) const
Return a point of the line at a distance lambda from its origin.
Definition: Segment3d.cc:107
bool downwards(void) const
Return true if the segment goes down.
Definition: Segment3d.cc:100
Posición en tres dimensiones.
Definition: Pos3d.h:44
VectorPos3d Divide(int num_partes) const
Return the points that results from the segment division.
Definition: Segment3d.cc:402
virtual GEOM_FT Iz(void) const
Moment of inertia with respect to the center of mass in local coordinates.
Definition: Segment3d.cc:396
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass in local coordinates.
Definition: Segment3d.cc:392
Line in a three-dimensional space.
Definition: Line3d.h:62
GEOM_FT getLambda(const Pos3d &p) const
Return the lambda parameter for the given point: p= getFromPoint()+lambda*VDir()
Definition: Segment3d.cc:160
virtual bool operator==(const Segment3d &) const
Comparison operator.
Definition: Segment3d.cc:58
virtual Vector3d getKVector(void) const
Returns a vector in the direction of the local Z axis.
Definition: Segment3d.cc:155
Vector de posiciones en tres dimensiones [(x1,y1,z1),(x1,y2,z2),...].
Definition: VectorPos3d.h:32
GEOM_FT getAngleYZPlane(void) const
Returns angle with the YZ plane.
Definition: Segment3d.cc:379
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
GEOM_FT dist(const Pos3d &p) const
Return the distance from the point to the segment.
Definition: Segment3d.cc:188
double getParamNaturalCoord(const GEOM_FT &) const
Return the parametric coordinate that corresponds to the natural coordinate being passed as parameter...
Definition: Segment3d.cc:116
GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const
Return the intersection of the line with the plane defined by the equation coord_i=cte.
Definition: Segment3d.cc:265
Vector en tres dimensiones.
Definition: Vector3d.h:39
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass in local coordinates.
Definition: Segment3d.cc:388