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 
70  GeomObj::list_Pos2d getVertices(void) const;
71  Vector2d getLado0Normal(const size_t i) const;
72  Vector2d getVertex0Normal(const size_t i) const;
73  int getIndexOfDistalEdge(const Pos2d &) const;
74  int getIndexOfProximalEdge(const Pos2d &) const;
75  int getIndexOfDistalVertex(const Pos2d &) const;
76  int getIndexOfProximalVertex(const Pos2d &) const;
77 
78  Polyline2d getPolyline(void) const;
79  virtual GEOM_FT getLength(void) const;
80  inline GEOM_FT getPerimeter(void) const
81  { return getLength(); }
82  virtual GEOM_FT getLengthUpTo(const Pos2d &) const;
83  inline GEOM_FT getLambda(const Pos2d &p) const
84  { return getLengthUpTo(p); }
85  inline GEOM_FT AreaSigno(void) const
86  { return moment_sign(0,0); }
87  virtual GEOM_FT getArea(void) const;
88  virtual GEOM_FT GetMax(unsigned short int i) const;
89  virtual GEOM_FT GetMin(unsigned short int i) const;
90  virtual Pos2d getCenterOfMass(void) const;
91  virtual Pos2d Centroide(void) const;
92  GEOM_FT getMoment(const int &p,const int &q) const;
93  virtual GEOM_FT Ix(void) const;
94  virtual GEOM_FT Iy(void) const;
95  virtual GEOM_FT Pxy(void) const;
96 
98 
99  GEOM_FT DistSigno(const Pos2d &p,const bool &clockwise= false) const;
100  GEOM_FT Dist(const Pos2d &p) const;
101  GEOM_FT getCover(const Pos2d &) const;
102  GEOM_FT getCover(const Pos2d &, const Vector2d &) const;
103 
104  bool Overlap(const Line2d &r) const;
105  bool Overlap(const Ray2d &sr) const;
106 
107  Segment2d Clip(const Line2d &) const;
108  Segment2d Clip(const Ray2d &) const;
109  Segment2d Clip(const Segment2d &) const;
110 
111 
112  void Print(std::ostream &os) const;
113  void Plot(Plotter &plotter) const;
114  };
115 
116 
117 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Line2d &r);
118 std::list<Segment2d> intersection(const Line2d &r,const PolygonalSurface2d &p);
119 
120 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Ray2d &sr);
121 std::list<Segment2d> intersection(const Ray2d &sr,const PolygonalSurface2d &p);
122 
123 std::list<Segment2d> intersection(const PolygonalSurface2d &p,const Segment2d &sg);
124 std::list<Segment2d> intersection(const Segment2d &sg,const PolygonalSurface2d &p);
125 
126 #endif
127 
128 
129 
virtual GEOM_FT getLengthUpTo(const Pos2d &) const
Return the length along the perimeter upto the given point.
Definition: PolygonalSurface2d.cc:588
Vector2d getLado0Normal(const size_t i) const
Return la normal al lado of the polygon.
Definition: PolygonalSurface2d.cc:45
Base class for position lists.
Definition: PolyPos.h:35
virtual Pos2d Centroide(void) const
Return the centroid (point interior to the polygon).
Definition: PolygonalSurface2d.cc:214
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:467
int getIndexOfProximalEdge(const Pos2d &) const
Return the proximal edge with respect to the point argument.
Definition: PolygonalSurface2d.cc:121
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:580
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:263
Vector en dos dimensiones.
Definition: Vector2d.h:40
Vector2d getVertex0Normal(const size_t i) const
Return la normal en el vértice of the polygon.
Definition: PolygonalSurface2d.cc:50
GeomObj::list_Pos2d getApproxTangentPositions(const Vector2d &) const
Return the points for which the polygon is almost tangent to the direction argument.
Definition: PolygonalSurface2d.cc:275
Base class for the polygonal surfaces.
Definition: PolygonalSurface2d.h:38
virtual GEOM_FT Iy(void) const
Calcula el moment of inertia with respect to an axis parallel to the y axis that passes through the p...
Definition: PolygonalSurface2d.cc:254
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:325
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:377
int getNearestEdgeIndex(const Pos2d &) const
Return the nearest edge to the given point.
Definition: PolygonalSurface2d.cc:529
virtual GEOM_FT getArea(void) const
Return the object area.
Definition: PolygonalSurface2d.cc:180
bool Overlap(const Line2d &r) const
Return true if the line and the polygonal surface overlap.
Definition: PolygonalSurface2d.cc:427
int getIndexOfDistalEdge(const Pos2d &) const
Return the distal edge with respect to the point argument.
Definition: PolygonalSurface2d.cc:101
int getIndexOfDistalVertex(const Pos2d &) const
Return the distal vertex with respect to the point argument.
Definition: PolygonalSurface2d.cc:141
Segment2d Lado0(unsigned int i, unsigned int j) const
Return the segments between vertices i and j (0->n).
Definition: PolygonalSurface2d.cc:73
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: PolygonalSurface2d.cc:194
Polyline2d getPolyline(void) const
Return the closed polyline formed with the vertices of the polygon.
Definition: PolygonalSurface2d.cc:63
virtual GEOM_FT Ix(void) const
Calcula el moment of inertia with respect to an axis parallel to the x axis que pasa por the center o...
Definition: PolygonalSurface2d.cc:245
GEOM_FT Dist(const Pos2d &p) const
Return the distance from the point to the polygon.
Definition: PolygonalSurface2d.cc:370
Segment2d getNearestEdge(const Pos2d &) const
Return the nearest edge to the given point.
Definition: PolygonalSurface2d.cc:563
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:161
GeomObj::list_Pos2d getVertices(void) const
Return los vertices of the polygon.
Definition: PolygonalSurface2d.cc:36
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:184
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:90
virtual Pos2d getCenterOfMass(void) const
Return the center of mass.
Definition: PolygonalSurface2d.cc:204
Segment2d Lado(unsigned int i) const
Return the i-th edge (i between 1 and num_sides).
Definition: PolygonalSurface2d.cc:86