xc
PolygonalSurface2d.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 //PolygonalSurface2D.h
22 
23 #ifndef POLYGONALSURFACE2D_H
24 #define POLYGONALSURFACE2D_H
25 
26 #include "utility/geom/d2/Surface2d.h"
27 
28 class Line2d;
29 class Ray2d;
30 class Segment2d;
31 class Polygon2d;
32 class Polyline2d;
33 
34 
36 //
39  {
40  private:
41  inline GEOM_FT a_i(unsigned int i) const
42  { return Vertice(i).x()*Vertice(i+1).y()-Vertice(i+1).x()*Vertice(i).y(); }
43  GEOM_FT moment_sign(const int &p,const int &q) const;
44  protected:
45  Segment2d Lado0(unsigned int i, unsigned int j) const;
46  public:
47  PolygonalSurface2d(void): Surface2d(){}
48 
49  virtual GeomObj *getCopy(void) const= 0;
50  inline virtual unsigned int getNumVertices(void) const
51  { return 0; }
52  inline virtual unsigned int getNumEdges(void) const
53  { return getNumVertices(); }
54  inline bool empty(void) const
55  { return (getNumVertices()<1); }
56  virtual Pos2d Vertice(unsigned int i) const= 0;
57  //Return el vértice de indice i (i=1..getNumVertices())
58  virtual Pos2d Vertice0(unsigned int j) const= 0;
59  //Return el vértice de indice j (j=0..getNumVertices()-1)
60  inline const Pos2d operator()(const size_t &i) const //Offset 1.
61  { return Vertice(i); }
62  inline const Pos2d operator[](const size_t &j) const //Offset 0.
63  { return Vertice0(j); }
64  Segment2d Lado(unsigned int i) const;
65  Segment2d Lado0(unsigned int i) const;
66  int getNearestEdgeIndex(const Pos2d &) const;
67  Segment2d getNearestEdge(const Pos2d &) const;
68  Pos2d Projection(const Pos2d &) const;
69 
71  boost::python::list getVertexListPy(void) const;
72  const std::list<Segment2d> getEdgeList(void) const;
73  boost::python::list getEdgeListPy(void) const;
74  Vector2d getLado0Normal(const size_t i) const;
75  Vector2d getVertex0Normal(const size_t i) const;
76  int getIndexOfDistalEdge(const Pos2d &) const;
77  int getIndexOfProximalEdge(const Pos2d &) const;
78  int getIndexOfDistalVertex(const Pos2d &) const;
79  int getIndexOfProximalVertex(const Pos2d &) const;
80 
81  Polyline2d getPolyline(void) const;
82  virtual GEOM_FT getLength(void) const;
83  inline GEOM_FT getPerimeter(void) const
84  { return getLength(); }
85  virtual GEOM_FT getLengthUpTo(const Pos2d &) const;
86  inline GEOM_FT getLambda(const Pos2d &p) const
87  { return getLengthUpTo(p); }
88  inline GEOM_FT AreaSigno(void) const
89  { return moment_sign(0,0); }
90  virtual GEOM_FT getArea(void) const;
91  virtual GEOM_FT GetMax(unsigned short int i) const;
92  virtual GEOM_FT GetMin(unsigned short int i) const;
93  virtual Pos2d getCenterOfMass(void) const;
94  virtual Pos2d Centroide(void) const;
95  GEOM_FT getMoment(const int &p,const int &q) const;
96  virtual GEOM_FT Ix(void) const;
97  virtual GEOM_FT Iy(void) const;
98  virtual GEOM_FT Pxy(void) const;
99 
101 
102  GEOM_FT DistSigno(const Pos2d &p,const bool &clockwise= false) const;
103  GEOM_FT Dist(const Pos2d &p) const;
104  GEOM_FT getCover(const Pos2d &) const;
105  GEOM_FT getCover(const Pos2d &, const Vector2d &) const;
106 
107  bool Overlap(const Line2d &r) const;
108  bool Overlap(const Ray2d &sr) const;
109 
110  Segment2d Clip(const Line2d &) const;
111  Segment2d Clip(const Ray2d &) const;
112  Segment2d Clip(const Segment2d &) const;
113 
114 
115  void Print(std::ostream &os) const;
116  void Plot(Plotter &plotter) const;
117  };
118 
119 
120 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Line2d &r);
121 std::list<Segment2d> intersection(const Line2d &r,const PolygonalSurface2d &p);
122 
123 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Ray2d &sr);
124 std::list<Segment2d> intersection(const Ray2d &sr,const PolygonalSurface2d &p);
125 
126 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Segment2d &sg);
127 std::list<Segment2d> intersection(const Segment2d &sg,const PolygonalSurface2d &p);
128 
129 #endif
130 
131 
132 
virtual GEOM_FT getLengthUpTo(const Pos2d &) const
Return the length along the perimeter upto the given point.
Definition: PolygonalSurface2d.cc:633
Vector2d getLado0Normal(const size_t i) const
Return la normal al lado of the polygon.
Definition: PolygonalSurface2d.cc:90
virtual Pos2d Centroide(void) const
Return the centroid (point interior to the polygon).
Definition: PolygonalSurface2d.cc:259
Posición en dos dimensiones.
Definition: Pos2d.h:41
Segment2d Clip(const Line2d &) const
Return the intersection of the polygon with the line (if exists).
Definition: PolygonalSurface2d.cc:512
int getIndexOfProximalEdge(const Pos2d &) const
Return the proximal edge with respect to the point argument.
Definition: PolygonalSurface2d.cc:166
Line in a two-dimensional space.
Definition: Line2d.h:61
Pos2d Projection(const Pos2d &) const
Return the projection of the given point into the polyline.
Definition: PolygonalSurface2d.cc:625
GeomObj::list_Pos2d getVertexList(void) const
Return the vertices of the polygon.
Definition: PolygonalSurface2d.cc:36
virtual GEOM_FT Pxy(void) const
Calcula el product of inertia with respect to the axis parallel to the axis x and y with origin in th...
Definition: PolygonalSurface2d.cc:308
boost::python::list getEdgeListPy(void) const
Return the edges of the polygon in a python list.
Definition: PolygonalSurface2d.cc:79
Vector en dos dimensiones.
Definition: Vector2d.h:41
Vector2d getVertex0Normal(const size_t i) const
Return la normal en el vértice of the polygon.
Definition: PolygonalSurface2d.cc:95
GeomObj::list_Pos2d getApproxTangentPositions(const Vector2d &) const
Return the points for which the polygon is almost tangent to the direction argument.
Definition: PolygonalSurface2d.cc:320
Base class for the polygonal surfaces.
Definition: PolygonalSurface2d.h:38
virtual GEOM_FT Iy(void) const
Compute the moment of inertia with respect to an axis parallel to the y axis through the center of ma...
Definition: PolygonalSurface2d.cc:299
Base class for surfaces in a two-dimensional space.
Definition: Surface2d.h:33
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
GEOM_FT DistSigno(const Pos2d &p, const bool &clockwise=false) const
Return the distance from the point to the perímeter The distance is computed as the maximum of: -The ...
Definition: PolygonalSurface2d.cc:370
Segment in a two-dimensional space.
Definition: Segment2d.h:38
GEOM_FT getCover(const Pos2d &) const
Return the distance from the point to the nearest edge.
Definition: PolygonalSurface2d.cc:422
int getNearestEdgeIndex(const Pos2d &) const
Return the nearest edge to the given point.
Definition: PolygonalSurface2d.cc:574
virtual GEOM_FT getArea(void) const
Return the object area.
Definition: PolygonalSurface2d.cc:225
bool Overlap(const Line2d &r) const
Return true if the line and the polygonal surface overlap.
Definition: PolygonalSurface2d.cc:472
int getIndexOfDistalEdge(const Pos2d &) const
Return the distal edge with respect to the point argument.
Definition: PolygonalSurface2d.cc:146
int getIndexOfDistalVertex(const Pos2d &) const
Return the distal vertex with respect to the point argument.
Definition: PolygonalSurface2d.cc:186
Segment2d Lado0(unsigned int i, unsigned int j) const
Return the segments between vertices i and j (0->n).
Definition: PolygonalSurface2d.cc:118
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: PolygonalSurface2d.cc:239
boost::python::list getVertexListPy(void) const
Return a Python list containing the positions of the polygon vertices.
Definition: PolygonalSurface2d.cc:46
Polyline2d getPolyline(void) const
Return the closed polyline formed with the vertices of the polygon.
Definition: PolygonalSurface2d.cc:108
virtual GEOM_FT Ix(void) const
Compute the moment of inertia with respect to an axis parallel to the x axis through the center of ma...
Definition: PolygonalSurface2d.cc:290
GEOM_FT Dist(const Pos2d &p) const
Return the distance from the point to the polygon.
Definition: PolygonalSurface2d.cc:415
Segment2d getNearestEdge(const Pos2d &) const
Return the nearest edge to the given point.
Definition: PolygonalSurface2d.cc:608
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
int getIndexOfProximalVertex(const Pos2d &) const
Return the proximal vertex with respect to the point argument.
Definition: PolygonalSurface2d.cc:206
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
virtual GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: PolygonalSurface2d.cc:229
const std::list< Segment2d > getEdgeList(void) const
Return the edges of the polygon.
Definition: PolygonalSurface2d.cc:57
Ray in a two-dimensional space.
Definition: Ray2d.h:35
virtual GEOM_FT getLength(void) const
Return the perimeter of the surface.
Definition: PolygonalSurface2d.cc:135
virtual Pos2d getCenterOfMass(void) const
Return the center of mass.
Definition: PolygonalSurface2d.cc:249
Segment2d Lado(unsigned int i) const
Return the i-th edge (i between 1 and num_sides).
Definition: PolygonalSurface2d.cc:131