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 
35 typedef std::pair<int,int> int_pair;
36 typedef std::deque<int_pair> int_pair_deque;
37 
39 //
41 class Segment3d : public Linear3d
42  {
43  CGSegment_3 cgseg;
44  public:
45  Segment3d(void);
46  Segment3d(const CGSegment_3 &r);
47  Segment3d(const Pos3d &p1,const Pos3d &p2);
48  virtual bool operator==(const Segment3d &) const;
49 
50  const CGSegment_3 &ToCGAL(void) const
51  { return cgseg; }
52  virtual GeomObj *getCopy(void) const;
53  void swap(void);
54  void TwoPoints(const Pos3d &p1,const Pos3d &p2);
55  virtual GEOM_FT GetMax(unsigned short int i) const;
56  virtual GEOM_FT GetMin(unsigned short int i) const;
57  Line3d getSupportLine(void) const;
58  Pos3d getFromPoint(void) const;
59  Pos3d getToPoint(void) const;
60  GEOM_FT getSlope(void) const;
61  bool upwards(void) const;
62  bool downwards(void) const;
63  const Pos3d Point(const int &i) const;
64  Pos3d PtoParametricas(const GEOM_FT &lambda) const;
65  Pos3d getMidPoint(void) const;
66  double getParamNaturalCoord(const GEOM_FT &) const;
67  Pos3d getPointNaturalCoord(const GEOM_FT &chi) const;
68  GEOM_FT getLambda(const Pos3d &p) const;
69  bool isDegenerated(void) const;
70  virtual bool In(const Pos3d &p, const double &tol= 0.0) const;
71  virtual GEOM_FT dist2(const Pos3d &p) const;
72  GEOM_FT dist(const Pos3d &p) const;
73  void Put(const Pos3d &p1,const Pos3d &p2);
74 
75  bool isParallel(const Line3d &r) const;
76  bool isParallel(const Ray3d &sr) const;
77  bool isParallel(const Segment3d &r) const;
78 
79  GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const;
83  bool connected(const Pos3d &, const GEOM_FT &tol= 0.0) const;
84 
85  Pos3d Projection(const Pos3d &) const;
86  Vector3d Projection(const Vector3d &) const;
87 
88  virtual GEOM_FT getLength(void) const;
89  virtual Pos3d getCenterOfMass(void) const;
90  Dir3d GetDir(void) const;
91  Vector3d VDir(void) const;
92  virtual Vector3d getIVector(void) const;
93  virtual Vector3d getJVector(void) const;
94  virtual Vector3d getKVector(void) const;
95  GEOM_FT getAngle(const Vector3d &v) const;
96  GEOM_FT getAngle(const Line3d &r) const;
97  GEOM_FT getAngle(const Ray3d &sr) const;
98  GEOM_FT getAngle(const Segment3d &v) const;
99  friend GEOM_FT angle(const Segment3d &r,const Vector3d &v);
100  virtual GEOM_FT Ix(void) const;
101  virtual GEOM_FT Iy(void) const;
102  virtual GEOM_FT Iz(void) const;
103 
104  VectorPos3d Divide(int num_partes) const;
105  boost::python::list DividePy(int num_partes) const;
106  VectorPos3d Divide(const std::vector<double> &) const;
107  boost::python::list DividePy(const boost::python::list &) const;
108  boost::python::list split(const Pos3d &) const;
109 
110  boost::python::dict getPyDict(void) const;
111  void setPyDict(const boost::python::dict &);
112 
113  void Print(std::ostream &os) const;
114  };
115 
116 inline GEOM_FT dist2(const Pos3d &p,const Segment3d &r)
117  { return r.dist2(p); }
118 inline GEOM_FT dist2(const Segment3d &r,const Pos3d &p)
119  { return dist2(p,r); }
120 GEOM_FT dist(const Pos3d &p,const Segment3d &r);
121 inline GEOM_FT dist(const Segment3d &r,const Pos3d &p)
122  { return dist(p,r); }
123 
124 inline bool parallel(const Segment3d &sg,const Line3d &r)
125  { return sg.isParallel(r); }
126 inline bool parallel(const Line3d &r, const Segment3d &sg)
127  { return parallel(sg,r); }
128 inline bool parallel(const Segment3d &sg,const Ray3d &sr)
129  { return sg.isParallel(sr); }
130 inline bool parallel(const Ray3d &sr, const Segment3d &sg)
131  { return parallel(sg,sr); }
132 inline bool parallel(const Segment3d &r1,const Segment3d &r2)
133  { return r1.isParallel(r2); }
134 
135 inline bool colineales(const Segment3d &sg,const Line3d &r)
136  { return colineales(sg.getSupportLine(),r); }
137 inline bool colineales(const Line3d &r,const Segment3d &sg)
138  { return colineales(sg,r); }
139 inline bool colineales(const Segment3d &sg,const Ray3d &sr)
140  { return colineales(sg.getSupportLine(),sr); }
141 inline bool colineales(const Ray3d &sr,const Segment3d &sg)
142  { return colineales(sg,sr); }
143 inline bool colineales(const Segment3d &sg1,const Segment3d &sg2)
144  { return colineales(sg1,sg2.getSupportLine()); }
145 
146 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg,const Line3d &r)
147  { return sg.getIntersection(r); }
148 inline GeomObj3d::list_Pos3d intersection(const Line3d &r, const Segment3d &sg)
149  { return sg.getIntersection(r); }
150 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg,const Ray3d &sr)
151  { return sg.getIntersection(sr); }
152 inline GeomObj3d::list_Pos3d intersection(const Ray3d &sr, const Segment3d &sg)
153  { return sg.getIntersection(sr); }
154 inline GeomObj3d::list_Pos3d intersection(const Segment3d &sg1,const Segment3d &sg2)
155  { return sg1.getIntersection(sg2); }
156 
157 int_pair_deque getIntersections(const std::deque<Segment3d> &);
158 
159 std::list<Polyline3d> get_polylines(const std::list<Segment3d> &, const GEOM_FT &tol);
160 boost::python::list py_get_3d_polylines(const boost::python::list &, const GEOM_FT &tol);
161 
162 #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:120
Pos3d Projection(const Pos3d &) const
Return the orthogonal projection onto the line.
Definition: Segment3d.cc:327
virtual GEOM_FT dist2(const Pos3d &p) const
Return the squared distance from the point to the segment.
Definition: Segment3d.cc:167
bool upwards(void) const
Return true if the segment goes up.
Definition: Segment3d.cc:95
GEOM_FT getAngle(const Vector3d &v) const
Returns the angle with the vector argument.
Definition: Segment3d.cc:346
virtual Vector3d getJVector(void) const
Returns a vector in the direction of the local Y axis.
Definition: Segment3d.cc:149
Segment en tres dimensiones.
Definition: Segment3d.h:41
virtual GeomObj * getCopy(void) const
Virtual constructor.
Definition: Segment3d.cc:72
Base class for position lists.
Definition: PolyPos.h:35
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Segment3d.cc:81
virtual GEOM_FT getLength(void) const
Return the length of the segment.
Definition: Segment3d.cc:198
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:312
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Segment3d.cc:466
void swap(void)
@ brief Swaps the segment orientation.
Definition: Segment3d.cc:76
boost::python::list DividePy(int num_partes) const
Return a Python list containing the points that results from the segment division.
Definition: Segment3d.cc:386
Pos3d getMidPoint(void) const
Return the mid point of the segment.
Definition: Segment3d.cc:110
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
virtual bool In(const Pos3d &p, const double &tol=0.0) const
Return true if the point is in the segment.
Definition: Segment3d.cc:126
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Segment3d.cc:475
GEOM_FT getSlope(void) const
Return the angle or the line with respect to XY plane.
Definition: Segment3d.cc:91
virtual Vector3d getIVector(void) const
Returns a vector in the direction of the local X axis.
Definition: Segment3d.cc:144
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:445
virtual GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: Segment3d.cc:79
Dirección en el espacio de tres dimensiones.
Definition: Dir3d.h:35
Segment3d(void)
Constructor.
Definition: Segment3d.cc:38
void Put(const Pos3d &p1, const Pos3d &p2)
Set the extremities of the segment.
Definition: Segment3d.cc:139
Pos3d PtoParametricas(const GEOM_FT &lambda) const
Return a point of the line at a distance lambda from its origin.
Definition: Segment3d.cc:106
bool downwards(void) const
Return true if the segment goes down.
Definition: Segment3d.cc:99
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:379
virtual GEOM_FT Iz(void) const
Moment of inertia with respect to the center of mass in local coordinates.
Definition: Segment3d.cc:373
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass in local coordinates.
Definition: Segment3d.cc:369
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:159
virtual bool operator==(const Segment3d &) const
Comparison operator.
Definition: Segment3d.cc:57
virtual Vector3d getKVector(void) const
Returns a vector in the direction of the local Z axis.
Definition: Segment3d.cc:154
Vector de posiciones en tres dimensiones [(x1,y1,z1),(x1,y2,z2),...].
Definition: VectorPos3d.h:32
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:187
double getParamNaturalCoord(const GEOM_FT &) const
Return the parametric coordinate that corresponds to the natural coordinate being passed as parameter...
Definition: Segment3d.cc:115
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:264
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:365