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 
95  VectorPos2d Divide(int num_partes) const;
96  boost::python::list DividePy(int num_partes) const;
97  VectorPos2d Divide(const std::vector<double> &) const;
98  boost::python::list DividePy(const boost::python::list &) const;
99 
101  inline virtual GEOM_FT Pxy(void) const
102  { return NAN; }
104  virtual GEOM_FT getLength(void) const
105  { return GeomObj::list_Pos2d::getLength(); }
106  virtual GEOM_FT getLengthUpTo(const Pos2d &) const;
107  inline GEOM_FT getLambda(const Pos2d &p) const
108  { return getLengthUpTo(p); }
109  virtual GEOM_FT GetMax(unsigned short int i) const;
110  //Return the maximum value of the i coordinate.
111  virtual GEOM_FT GetMin(unsigned short int i) const;
113  Polyline2d GetMayores(unsigned short int i,const GEOM_FT &d) const;
114  Polyline2d GetMenores(unsigned short int i,const GEOM_FT &d) const;
115  const Pos2d &Vertice(const size_t &) const;
116  const Pos2d &Vertice0(const size_t &) const;
117  Segment2d getSegment(const const_iterator &i) const;
118  Segment2d getSegment(const size_t &i) const;
119  Segment2d getSegment0(const size_t &i) const;
120  std::vector<Segment2d> getSegments(void) const;
121  const_iterator getNearestSegmentIter(const Pos2d &) const;
122  int getNearestSegmentIndex(const Pos2d &) const;
123  Segment2d getNearestSegment(const Pos2d &) const;
124  Pos2d Projection(const Pos2d &) const;
125  Polyline2d offset(const GEOM_FT &d) const;
126  Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices= 8) const;
127 
128  std::deque<const_iterator> getIntersectionIters(const Line2d &) const;
129  list_Pos2d getIntersection(const Line2d &r) const;
130  list_Pos2d getIntersection(const Ray2d &sr) const;
131  list_Pos2d getIntersection(const Segment2d &sr) const;
132  std::deque<Polyline2d> clip(const HalfPlane2d &, const GEOM_FT &tol= 0.0) const;
133  boost::python::list clipPy(const HalfPlane2d &, const GEOM_FT &tol= 0.0) const;
134  void insertVertex(const Pos2d &, const GEOM_FT &tol= 1e-6);
135  Polyline2d getChunk(const Pos2d &,const short int &, const GEOM_FT &tol) const;
136  Polyline2d getLeftChunk(const Pos2d &, const GEOM_FT &tol) const;
137  Polyline2d getRightChunk(const Pos2d &, const GEOM_FT &tol) const;
138  boost::python::list split(const Pos2d &) const;
139  Pos2d getCenterOfMass(void) const
141 
142  iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist);
143 
144  boost::python::dict getPyDict(void) const;
145  void setPyDict(const boost::python::dict &);
146 
147  void Print(std::ostream &stream) const;
148  void Plot(Plotter &) const;
149  };
150 
151 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Line2d &r);
152 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Ray2d &);
153 GeomObj::list_Pos2d intersection(const Polyline2d &p,const Segment2d &);
154 GeomObj::list_Pos2d intersection(const Line2d &,const Polyline2d &);
155 GeomObj::list_Pos2d intersection(const Ray2d &,const Polyline2d &p);
156 GeomObj::list_Pos2d intersection(const Segment2d &,const Polyline2d &p);
157 
158 #endif
159 
160 
161 
162 
163 
164 
VectorPos2d Divide(int num_partes) const
Return the points that results from the division of the polyline.
Definition: Polyline2d.cc:673
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:452
iterator getFarthestPointFromSegment(iterator it1, iterator it2, GEOM_FT &pMaxDist)
Definition: Polyline2d.cc:1031
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i coordinate.
Definition: Polyline2d.cc:256
std::vector< Vector2d > getCurvatureVectorAtVertices(void) const
Return the approximate curvature of the polyline at each of its vertices.
Definition: Polyline2d.cc:526
virtual GEOM_FT Iz(void) const
Moment of inertia polar with respect to the center of mass en local axis.
Definition: Polyline2d.cc:760
const_iterator getNearestSegmentIter(const Pos2d &) const
Return the nearest segment to the given point.
Definition: Polyline2d.cc:183
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the point is in the polyline.
Definition: Polyline2d.cc:121
Base class for position lists.
Definition: PolyPos.h:35
void setVertices(const boost::python::list &)
Set the polyline vertices from the given Python list.
Definition: Polyline2d.cc:92
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:107
const Pos2d & Vertice(const size_t &) const
Return the i-th vertex (the first one has the index 1).
Definition: Polyline2d.cc:311
Segment2d getNearestSegment(const Pos2d &) const
Return the nearest 2D segment.
Definition: Polyline2d.cc:221
pos getCenterOfMass(void) const
Return the center of mass del polígono.
Definition: PolyPos.h:353
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:836
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:830
int getNearestSegmentIndex(const Pos2d &) const
Return the index of the nearest 3D segment.
Definition: Polyline2d.cc:213
virtual GEOM_FT Pxy(void) const
Inertia product.
Definition: Polyline2d.h:101
Polyline2d offset(const GEOM_FT &d) const
Return a polyline parallel to this one at the distance being passed as parameter. ...
Definition: Polyline2d.cc:321
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:117
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:790
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:68
GEOM_FT dist(const Pos2d &p) const
Return the distance from the point to the segment.
Definition: Polyline2d.cc:178
Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices=8) const
Return a buffer polygon around the segment.
Definition: Polyline2d.cc:334
Segment2d getSegment0(const size_t &i) const
Return i-th segment (the first one is the 0).
Definition: Polyline2d.cc:380
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:841
Vector en dos dimensiones.
Definition: Vector2d.h:40
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:872
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:577
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:252
Polyline2d GetMayores(unsigned short int i, const GEOM_FT &d) const
Return the minimum value of the i coordinate.
Definition: Polyline2d.cc:261
GEOM_FT getCurvatureAtVertex(const_iterator) const
Return the approximate curvature of the polyline at the vertex pointed by the iterator argument...
Definition: Polyline2d.cc:416
const Pos2d & Vertice0(const size_t &) const
Return the i-th vertex (the first one has the index 0).
Definition: Polyline2d.cc:315
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:485
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:269
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:636
Polyline2d(void)
Default constructor.
Definition: Polyline2d.cc:37
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: Polyline2d.h:104
Pos2d Projection(const Pos2d &) const
Return the projection of the given point into the polyline.
Definition: Polyline2d.cc:244
std::vector< Segment2d > getSegments(void) const
Return a vector containing the consecutive segments of the polyline.
Definition: Polyline2d.cc:393
const GeomObj::list_Pos2d & getVertices(void) const
Return the list of the vertices.
Definition: Polyline2d.cc:83
Segment2d getSegment(const const_iterator &i) const
Return the segment that follows the *i vertex.
Definition: Polyline2d.cc:353
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:652
virtual GEOM_FT getLengthUpTo(const Pos2d &) const
Return the length along the polyline upto the given point.
Definition: Polyline2d.cc:139
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:770
GEOM_FT getLength(void) const
Return the length of the PolyPos.
Definition: PolyPos.h:169
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:690
const Pos2d * appendVertex(const Pos2d &)
Append a vertex to the polyline.
Definition: Polyline2d.cc:61
list_Pos2d getIntersection(const Line2d &r) const
Return the points of intersection of the polyline with the argument.
Definition: Polyline2d.cc:891
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:101
boost::python::list getVertexListPy(void) const
Return a Python list containing the positions of the polyline vertices.
Definition: Polyline2d.cc:106
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:942
Pos2d getPointAtLength(const GEOM_FT &) const
Return the point at a distance "s" measured along the polyline from its origin.
Definition: Polyline2d.cc:618
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:1059
virtual GEOM_FT dist2(const Pos2d &p) const
Return the squared distance to the polyline.
Definition: Polyline2d.cc:160
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Polyline2d.cc:748
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Polyline2d.cc:1068
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Polyline2d.cc:754
List of 2D positions.
Definition: Pos2dList.h:33