xc
Polyline2d.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 //Polyline2d.h
22 
23 #ifndef POLYLINE2D_H
24 #define POLYLINE2D_H
25 
26 #include "../pos_vec/Pos2d.h"
27 #include "Linear2d.h"
28 
29 class Segment2d;
30 class Ray2d;
31 class Line2d;
32 class HalfPlane2d;
33 class Pos2dList;
34 class Polygon2d;
35 class Circle2d;
36 class VectorPos2d;
37 
39 //
41 class Polyline2d : public Linear2d, public GeomObj::list_Pos2d
42  {
43  public:
44  Polyline2d(void);
45  explicit Polyline2d(const GeomObj::list_Pos2d &);
46  explicit Polyline2d(const Pos2dList &);
47  explicit Polyline2d(const boost::python::list &);
48  explicit Polyline2d(const Polygon2d &);
49 
50  virtual GeomObj *getCopy(void) const
51  { return new Polyline2d(*this); }
52  const GeomObj::list_Pos2d &getVertices(void) const;
53  const GeomObj::list_Pos2d &getVertexList(void) const;
54  boost::python::list getVertexListPy(void) const;
55  inline size_t getNumVertices(void) const
56  { return GeomObj::list_Pos2d::size(); }
57  size_t getNumSegments(void) const;
58  void setVertices(const boost::python::list &);
59  inline const_iterator vertices_begin(void) const
60  { return GeomObj::list_Pos2d::begin(); }
61  const const_iterator vertices_end(void) const
62  { return GeomObj::list_Pos2d::end(); }
63 
64  void Transform(const Trf2d &trf2d);
65 
66 /* inline virtual void GiraX(double ang) */
67 /* { Ref2d::GiraX(ang); TrfPoints(); } */
68 /* inline virtual void GiraY(double ang) */
69 /* { Ref2d::GiraY(ang); TrfPoints(); } */
70 /* inline virtual void GiraZ(double ang) */
71 /* { Ref2d::GiraZ(ang); TrfPoints(); } */
72  const Pos2d *appendVertex(const Pos2d &);
73  const Pos2d *appendVertexLeft(const Pos2d &);
75  template <class InputIterator>
76  inline void assign(InputIterator first, InputIterator last)
77  { GeomObj::list_Pos2d::assign(first,last); }
78  virtual bool In(const Pos2d &p, const double &tol= 0.0) const;
79  virtual GEOM_FT dist2(const Pos2d &p) const;
80  GEOM_FT dist(const Pos2d &p) const;
81 
82  virtual GEOM_FT Ix(void) const;
83  virtual GEOM_FT Iy(void) const;
84  virtual GEOM_FT Iz(void) const;
85 
86  GEOM_FT getCurvatureAtVertex(const_iterator) const;
87  GEOM_FT getCurvatureAtLength(const GEOM_FT &) const;
88  Vector2d getCurvatureVectorAtVertex(const_iterator) const;
89  std::vector<Vector2d> getCurvatureVectorAtVertices(void) const;
90  Vector2d getCurvatureVectorAtLength(const GEOM_FT &) const;
91  Pos2d getPointAtLength(const GEOM_FT &) const;
92  Vector2d getIVectorAtLength(const GEOM_FT &) const;
93  Vector2d getJVectorAtLength(const GEOM_FT &) const;
94  std::vector<Vector2d> getTangentVectorAtVertices(void) const;
95  boost::python::list getTangentVectorAtVerticesPy(void) const;
96  std::vector<Vector2d> getNormalVectorAtVertices(void) const;
97  boost::python::list getNormalVectorAtVerticesPy(void) const;
98 
99  VectorPos2d Divide(int num_partes) const;
100  boost::python::list DividePy(int num_partes) const;
101  VectorPos2d Divide(const std::vector<double> &) const;
102  boost::python::list DividePy(const boost::python::list &) const;
103 
105  inline virtual GEOM_FT Pxy(void) const
106  { return NAN; }
108  virtual GEOM_FT getLength(void) const
109  { return GeomObj::list_Pos2d::getLength(); }
110  virtual GEOM_FT getLengthUpTo(const Pos2d &) const;
111  inline GEOM_FT getLambda(const Pos2d &p) const
112  { return getLengthUpTo(p); }
113  virtual GEOM_FT GetMax(unsigned short int i) const;
114  //Return the maximum value of the i coordinate.
115  virtual GEOM_FT GetMin(unsigned short int i) const;
117  Polyline2d GetMayores(unsigned short int i,const GEOM_FT &d) const;
118  Polyline2d GetMenores(unsigned short int i,const GEOM_FT &d) const;
119  const Pos2d &Vertice(const size_t &) const;
120  const Pos2d &Vertice0(const size_t &) const;
121  Segment2d getSegment(const const_iterator &i) const;
122  Segment2d getSegment(const size_t &i) const;
123  Segment2d getSegment0(const size_t &i) const;
124  std::vector<Segment2d> getSegments(void) const;
125  const_iterator getNearestSegmentIter(const Pos2d &) const;
126  int getNearestSegmentIndex(const Pos2d &) const;
127  Segment2d getNearestSegment(const Pos2d &) const;
128  Pos2d Projection(const Pos2d &) const;
129  Polyline2d offset(const GEOM_FT &d) const;
130  Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices= 8) const;
131 
132  std::deque<const_iterator> getIntersectionIters(const Line2d &) const;
133  list_Pos2d getIntersection(const Line2d &r) const;
134  list_Pos2d getIntersection(const Ray2d &sr) const;
135  list_Pos2d getIntersection(const Segment2d &sr) const;
136  std::deque<Polyline2d> clip(const HalfPlane2d &, const GEOM_FT &tol= 0.0) const;
137  boost::python::list clipPy(const HalfPlane2d &, const GEOM_FT &tol= 0.0) const;
138  void insertVertex(const Pos2d &, const GEOM_FT &tol= 1e-6);
139  Polyline2d getChunk(const Pos2d &,const short int &, const GEOM_FT &tol) const;
140  Polyline2d getLeftChunk(const Pos2d &, const GEOM_FT &tol) const;
141  Polyline2d getRightChunk(const Pos2d &, const GEOM_FT &tol) const;
142  boost::python::list split(const Pos2d &) const;
143  Pos2d getCenterOfMass(void) const
145 
146  iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist);
147 
148  boost::python::dict getPyDict(void) const;
149  void setPyDict(const boost::python::dict &);
150 
151  void Print(std::ostream &stream) const;
152  void Plot(Plotter &) const;
153  };
154 
155 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Line2d &r);
156 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Ray2d &);
157 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Segment2d &);
158 GeomObj::list_Pos2d intersection(const Line2d &,const Polyline2d &);
159 GeomObj::list_Pos2d intersection(const Ray2d &,const Polyline2d &p);
160 GeomObj::list_Pos2d intersection(const Segment2d &,const Polyline2d &p);
161 Polyline2d remove_duplicated_vertices(const Polyline2d &p,const GEOM_FT &tol= -1.0);
162 
163 #endif
164 
165 
166 
167 
168 
169 
VectorPos2d Divide(int num_partes) const
Return the points that results from the division of the polyline.
Definition: Polyline2d.cc:769
GEOM_FT getCurvatureAtLength(const GEOM_FT &) const
Return the approximate curvature of the polyline at the the point at a distance "s" measured along th...
Definition: Polyline2d.cc:456
iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist)
Definition: Polyline2d.cc:1146
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i coordinate.
Definition: Polyline2d.cc:257
std::vector< Vector2d > getCurvatureVectorAtVertices(void) const
Return the approximate curvature of the polyline at each of its vertices.
Definition: Polyline2d.cc:531
const_iterator getNearestSegmentIter(const Pos2d &) const
Return the nearest segment to the given point.
Definition: Polyline2d.cc:184
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the point is in the polyline.
Definition: Polyline2d.cc:122
void setVertices(const boost::python::list &)
Set the polyline vertices from the given Python list.
Definition: Polyline2d.cc:93
void assign(InputIterator first, InputIterator last)
Insert the vertices between [first,last) antes.
Definition: Polyline2d.h:76
Círculo en dos dimensiones.
Definition: Circle2d.h:37
GEOM_FT getLambda(const Pos2d &p) const
Return the lambda parameter for the given point: p= getFromPoint()+lambda*VDir()
Definition: Polyline2d.h:111
const Pos2d & Vertice(const size_t &) const
Return the i-th vertex (the first one has the index 1).
Definition: Polyline2d.cc:312
Segment2d getNearestSegment(const Pos2d &) const
Return the nearest 2D segment.
Definition: Polyline2d.cc:222
Pos2d getCenterOfMass(void) const
Return the center of mass del polígono.
Definition: PolyPos.h:363
Polyline2d getRightChunk(const Pos2d &, const GEOM_FT &tol) const
Return the polyline chunk that goes the nearest vertex to to p to its end.
Definition: Polyline2d.cc:951
Posición en dos dimensiones.
Definition: Pos2d.h:41
Polyline2d getLeftChunk(const Pos2d &, const GEOM_FT &tol) const
Return the polyline chunk that goes from its beginning to the nearest vertex to p.
Definition: Polyline2d.cc:945
int getNearestSegmentIndex(const Pos2d &) const
Return the index of the nearest 3D segment.
Definition: Polyline2d.cc:214
std::vector< Vector2d > getNormalVectorAtVertices(void) const
Compute the normal vectors at each of the polyline vertices.
Definition: Polyline2d.cc:654
virtual GEOM_FT Pxy(void) const
Inertia product.
Definition: Polyline2d.h:105
Polyline2d offset(const GEOM_FT &d) const
Return a polyline parallel to this one at the distance being passed as parameter. ...
Definition: Polyline2d.cc:322
Line in a two-dimensional space.
Definition: Line2d.h:61
void Transform(const Trf2d &trf2d)
Applies the transformation to the points que se pasa como parámetro.
Definition: Polyline2d.cc:118
Polyline2d getChunk(const Pos2d &, const short int &, const GEOM_FT &tol) const
Assuming that p is a vertex of the polyline Return the chunk: from the beginning to p if sgn < 0 from...
Definition: Polyline2d.cc:890
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
const Pos2d * appendVertexLeft(const Pos2d &)
Append a vertex to the beginning of the polyline.
Definition: Polyline2d.cc:69
GEOM_FT dist(const Pos2d &p) const
Return the distance from the point to the segment.
Definition: Polyline2d.cc:179
Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices=8) const
Return a buffer polygon around the segment.
Definition: Polyline2d.cc:335
Segment2d getSegment0(const size_t &i) const
Return i-th segment (the first one is the 0).
Definition: Polyline2d.cc:383
boost::python::list split(const Pos2d &) const
Return the two polylines that result from splitting this one on the point nearest to the argument...
Definition: Polyline2d.cc:956
Vector en dos dimensiones.
Definition: Vector2d.h:41
std::deque< const_iterator > getIntersectionIters(const Line2d &) const
Return the iterators to the origin vertices of the polyline segments where the intersection with the ...
Definition: Polyline2d.cc:987
Vector2d getCurvatureVectorAtLength(const GEOM_FT &) const
Return the approximate curvature vector of the polyline at the the point at a distance "s" measured a...
Definition: Polyline2d.cc:581
Vector de posiciones en dos dimensiones [(x1,y1),(x1,y2),...].
Definition: VectorPos2d.h:33
virtual GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i coordinate.
Definition: Polyline2d.cc:253
Polyline2d GetMayores(unsigned short int i, const GEOM_FT &d) const
Return the minimum value of the i coordinate.
Definition: Polyline2d.cc:262
GEOM_FT getCurvatureAtVertex(const_iterator) const
Return the approximate curvature of the polyline at the vertex pointed by the iterator argument...
Definition: Polyline2d.cc:420
const Pos2d & Vertice0(const size_t &) const
Return the i-th vertex (the first one has the index 0).
Definition: Polyline2d.cc:316
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
Segment in a two-dimensional space.
Definition: Segment2d.h:38
Vector2d getCurvatureVectorAtVertex(const_iterator) const
Return the approximate curvature of the polyline at the vertex pointed by the iterator argument...
Definition: Polyline2d.cc:489
Polyline2d GetMenores(unsigned short int i, const GEOM_FT &d) const
Return a Polyline2d with the vertices whose i-th coordinate is smaller than d.
Definition: Polyline2d.cc:270
Vector2d getIVectorAtLength(const GEOM_FT &) const
Return the I vector of the segment that lies at the point at a distance "s" measured along the polyli...
Definition: Polyline2d.cc:732
Polyline2d(void)
Default constructor.
Definition: Polyline2d.cc:38
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: Polyline2d.h:108
Pos2d Projection(const Pos2d &) const
Return the projection of the given point into the polyline.
Definition: Polyline2d.cc:245
std::vector< Segment2d > getSegments(void) const
Return a vector containing the consecutive segments of the polyline.
Definition: Polyline2d.cc:397
const GeomObj::list_Pos2d & getVertices(void) const
Return the list of the vertices.
Definition: Polyline2d.cc:84
Segment2d getSegment(const const_iterator &i) const
Return the segment that follows the *i vertex.
Definition: Polyline2d.cc:354
Vector2d getJVectorAtLength(const GEOM_FT &) const
Return the J vector of the segment that lies at the point at a distance "s" measured along the polyli...
Definition: Polyline2d.cc:748
virtual GEOM_FT getLengthUpTo(const Pos2d &) const
Return the length along the polyline upto the given point.
Definition: Polyline2d.cc:140
void insertVertex(const Pos2d &, const GEOM_FT &tol=1e-6)
Insert the point argument as vertex by splitting the nearest segment if the nearest vertex is not clo...
Definition: Polyline2d.cc:870
GEOM_FT getLength(void) const
Return the length of the PolyPos.
Definition: PolyPos.h:178
Half plane in a two-dimensional space.
Definition: HalfPlane2d.h:38
boost::python::list DividePy(int num_partes) const
Return a Python list containing the points that results from the division of the polyline.
Definition: Polyline2d.cc:786
const Pos2d * appendVertex(const Pos2d &)
Append a vertex to the polyline.
Definition: Polyline2d.cc:62
list_Pos2d getIntersection(const Line2d &r) const
Return the points of intersection of the polyline with the argument.
Definition: Polyline2d.cc:1006
boost::python::list getNormalVectorAtVerticesPy(void) const
Return a Python list containing the normal vectors at each of the polyline vertices.
Definition: Polyline2d.cc:700
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
const GeomObj::list_Pos2d & getVertexList(void) const
Return the list of the vertices.
Definition: Polyline2d.cc:102
boost::python::list getVertexListPy(void) const
Return a Python list containing the positions of the polyline vertices.
Definition: Polyline2d.cc:107
std::vector< Vector2d > getTangentVectorAtVertices(void) const
Compute the tangent vectors at each of the polyline vertices.
Definition: Polyline2d.cc:620
boost::python::list getTangentVectorAtVerticesPy(void) const
Return a Python list containing the tangent vectors at each of the polyline vertices.
Definition: Polyline2d.cc:643
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
std::deque< Polyline2d > clip(const HalfPlane2d &, const GEOM_FT &tol=0.0) const
Return the polyline chunks that result from clippin this polyline with the given half space...
Definition: Polyline2d.cc:1057
Pos2d getPointAtLength(const GEOM_FT &) const
Return the point at a distance "s" measured along the polyline from its origin.
Definition: Polyline2d.cc:714
Ray in a two-dimensional space.
Definition: Ray2d.h:35
Base class for the objects involving a single dimension in a two-dimensional space.
Definition: Linear2d.h:34
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Polyline2d.cc:1174
virtual GEOM_FT dist2(const Pos2d &p) const
Return the squared distance to the polyline.
Definition: Polyline2d.cc:161
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Polyline2d.cc:845
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Polyline2d.cc:1183
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to an axis parallel to the Y axis that passes through the center of ma...
Definition: Polyline2d.cc:852
List of 2D positions.
Definition: Pos2dList.h:33