xc
Polygon3d.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 //Polygon3d.h
22 
23 #ifndef POLYGON3D_H
24 #define POLYGON3D_H
25 
26 #include "utility/geom/d2/D2to3d.h"
27 #include "utility/geom/pos_vec/Vector3d.h"
28 #include "utility/geom/d2/2d_polygons/Polygon2d.h"
29 #include "../cgal_types.h"
30 #include "utility/geom/d2/Plane.h"
31 
33 //
35 class Polygon3d: public D2to3d
36  {
37  Polygon2d plg2d;
38  public:
39  Polygon3d(void): D2to3d(),plg2d() {}
40  template <typename InputIterator>
41  explicit Polygon3d(InputIterator first,InputIterator last);
42  Polygon3d(const Pos3d &p1,const Pos3d &p2,const Pos3d &p3);
43  Polygon3d(const Ref2d3d &,const Polygon2d &p= Polygon2d());
44  Polygon3d(const Ref3d3d &,const Polygon2d &p= Polygon2d());
45  explicit Polygon3d(const GeomObj::list_Pos3d &);
46  explicit Polygon3d(const boost::python::list &);
47 
48  virtual GeomObj *getCopy(void) const
49  { return new Polygon3d(*this); }
50 
51  inline void push_back(const Pos3d &p)
52  { plg2d.push_back(to_2d(p)); }
53 
54  inline virtual unsigned int getNumVertices(void) const
55  { return plg2d.getNumVertices(); }
56  inline virtual unsigned int getNumEdges(void) const
57  { return plg2d.getNumEdges(); }
59  inline GEOM_FT getLength(void) const
60  { return plg2d.getLength(); }
62  inline GEOM_FT getArea(void) const
63  { return plg2d.getArea(); }
64  std::vector<Polygon3d> getTributaryPolygons(void) const;
65  inline std::vector<double> getTributaryAreas(void) const
66  { return plg2d.getTributaryAreas(); }
68  inline Pos3d Vertice(unsigned int i) const
69  { return to_3d(plg2d.Vertice(i)); }
72  inline Pos3d Vertice0(unsigned int j) const
73  { return to_3d(plg2d.Vertice0(j)); }
75  boost::python::list getVertexListPy(void) const;
76  Segment3d Lado0(unsigned int i) const;
77  Segment3d Lado(unsigned int i) const;
78  int getIndexOfDistalEdge(const Pos3d &) const;
79  int getIndexOfProximalEdge(const Pos3d &) const;
80  int getIndexOfDistalVertex(const Pos3d &) const;
81  int getIndexOfProximalVertex(const Pos3d &) const;
82 
83  bool clockwise(const Pos3d &) const;
84  bool counterclockwise(const Pos3d &) const;
85  void swap(void);
86  std::string orientation(const Pos3d &) const;
87 
88  Pos3d Projection(const Pos3d &) const;
89  virtual GEOM_FT getLengthUpTo(const Pos3d &) const;
90  inline GEOM_FT getLambda(const Pos3d &p) const
91  { return getLengthUpTo(p); }
92 
93  Polygon3d offset(const GEOM_FT &d) const;
94  Polygon3d buffer(const GEOM_FT &d) const;
95 
96  Plane getPlaneFromSide0(unsigned int i) const;
97  Plane getPlaneFromSide(unsigned int i) const;
98 
99  Pos3d getCenterOfMass(void) const;
100  GEOM_FT Ix(void) const;
101  GEOM_FT Iy(void) const;
102  GEOM_FT Iz(void) const;
103 
104  GEOM_FT GetMax(unsigned short int i) const;
105  GEOM_FT GetMin(unsigned short int i) const;
106  bool In(const Pos3d &p,const double &tol) const;
107  bool TocaCuadrante(const int &) const;
108 
109  GEOM_FT distSigno(const Pos3d &p) const;
110  GEOM_FT dist(const Pos3d &p) const;
111  GEOM_FT distSigno2(const Pos3d &p) const;
112  GEOM_FT dist2(const Pos3d &p) const;
113 
114  Segment3d Clip(const Line3d &) const;
115  Segment3d Clip(const Ray3d &) const;
116  Segment3d Clip(const Segment3d &) const;
117 
118  bool intersects(const Line3d &) const;
119  Segment3d getIntersection(const Line3d &) const;
120  bool intersects(const Plane &) const;
121  Segment3d getIntersection(const Plane &) const;
122  std::list<Polygon3d> Corta(const Plane &p) const;
123 
124  void Print(std::ostream &os) const;
125  };
126 
127 template <typename InputIterator>
128 Polygon3d::Polygon3d(InputIterator begin,InputIterator end)
129  : D2to3d(), plg2d()
130  {
131  Plane p(begin, end);
132  auto i= begin;
133  const Pos3d A= *i; i++;
134  const Pos3d B= *i; i++;
135  const Pos3d C= *i;
136  const Ref2d3d ref= Ref2d3d(*begin,p.Base1(), p.Base2());
137  Polygon3d tmp(ref);
138  for(InputIterator i= begin; i!= end; i++)
139  tmp.push_back(*i);
140  (*this)= tmp;
141 
142  }
143 
144 inline std::list<Polygon3d> corta(const Polygon3d &pol,const Plane &pl)
145  { return pol.Corta(pl); }
146 
147 #endif
Pos2d to_2d(const Pos3d &) const
Return the 2D point corresponding to the 3D point argument.
Definition: D2to3d.cc:132
GEOM_FT Iz(void) const
Moment of inertia with respect to an axis parallel to the z axis passing through the center of mass...
Definition: Polygon3d.cc:254
int getIndexOfProximalEdge(const Pos3d &) const
Return the proximal edge with respect to the point argument.
Definition: Polygon3d.cc:131
Segment3d Lado0(unsigned int i) const
Return the i-th side (i between 0 and num_sides-1).
Definition: Polygon3d.cc:102
Plane polygon in a 3D space.
Definition: Polygon3d.h:35
std::string orientation(const Pos3d &) const
Return the orientation of the polygon (clockwise or counterclockwise).
Definition: Polygon3d.cc:537
GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: Polygon3d.cc:261
GeomObj::list_Pos3d getVertexList(void) const
Return a Python list containing the positions of the polygon vertices.
Definition: Polygon3d.cc:73
Segment en tres dimensiones.
Definition: Segment3d.h:41
GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Polygon3d.cc:266
Base class for position lists.
Definition: PolyPos.h:35
Pos3d Projection(const Pos3d &) const
Return the projection of the given point into the polyline.
Definition: Polygon3d.cc:515
Segment3d getIntersection(const Line3d &) const
Return the intersection with the line argument.
Definition: Polygon3d.cc:419
int getIndexOfProximalVertex(const Pos3d &) const
Return the proximal vertex with respect to the point argument.
Definition: Polygon3d.cc:171
Pos3d Vertice(unsigned int i) const
Return the position of the i-th vertex.
Definition: Polygon3d.h:68
GEOM_FT Ix(void) const
Moment of inertia with respect to an axis parallel to the x axis passing through the center of mass...
Definition: Polygon3d.cc:236
Pos2d Vertice(unsigned int i) const
Return the position of the i-th vertex.
Definition: Polygon2d.h:157
Segment3d Lado(unsigned int i) const
Return the i-th edge (i between 1 and num_sides).
Definition: Polygon3d.cc:95
Vector3d Base1(void) const
Return un vector ortogonal al devuelto por Normal().
Definition: Plane.cc:145
Plane in a three-dimensional space.
Definition: Plane.h:49
virtual GEOM_FT getLengthUpTo(const Pos3d &) const
Return the length along the perimeter upto the given point.
Definition: Polygon3d.cc:526
Pos2d Vertice0(unsigned int j) const
Return the position of the i-th vertex (0 based: j=0..getNumVertices()-1).
Definition: Polygon2d.h:161
bool TocaCuadrante(const int &) const
Return true if alguno de los vertices toca el cuadrante que se pasa como parámetro.
Definition: Polygon3d.cc:457
Polygon3d offset(const GEOM_FT &d) const
Return a polygon parallel to this one at the given distance.
Definition: Polygon3d.cc:498
Segment3d Clip(const Line3d &) const
Return the intersection of the polygon with the line.
Definition: Polygon3d.cc:340
Ray in a three-dimensional space.
Definition: Ray3d.h:36
std::list< Polygon3d > Corta(const Plane &p) const
Return the polygons that result form cutting the polygon with the argument plane. ...
Definition: Polygon3d.cc:436
bool counterclockwise(const Pos3d &) const
Return true if the point list is oriented counterclockwise.
Definition: Polygon3d.cc:473
int getIndexOfDistalVertex(const Pos3d &) const
Return the distal vertex with respect to the point argument.
Definition: Polygon3d.cc:151
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
bool In(const Pos3d &p, const double &tol) const
Return true if the point lies inside the polygon (i.
Definition: Polygon3d.cc:202
Pos3d getCenterOfMass(void) const
Return the center of mass of the polygon.
Definition: Polygon3d.cc:218
Polygon3d buffer(const GEOM_FT &d) const
Returns the buffer (a polygon being the spatial point set collection within a specified maximum dista...
Definition: Polygon3d.cc:507
Class that places 2D objects (circle, ellipse, polygons, ...) in a 3D space.
Definition: D2to3d.h:44
GEOM_FT getArea(void) const
Return the area of the object.
Definition: Polygon3d.h:62
boost::python::list getVertexListPy(void) const
Return a Python list containing the positions of the polygon vertices.
Definition: Polygon3d.cc:84
Vector3d Base2(void) const
Return un vector ortogonal al devuelto por Normal() y al devuelto por Base1().
Definition: Plane.cc:152
D2to3d(void)
Constructor.
Definition: D2to3d.cc:40
GEOM_FT dist2(const Pos3d &p) const
Return the distance from point to polygon.
Definition: Polygon3d.cc:321
bool clockwise(const Pos3d &) const
Return true if the point list is oriented clockwise.
Definition: Polygon3d.cc:468
std::vector< double > getTributaryAreas(void) const
Return the areas of the tributary polygons (one for each vertex).
Definition: Polygon2d.cc:415
Posición en tres dimensiones.
Definition: Pos3d.h:44
GEOM_FT Iy(void) const
Moment of inertia with respect to an axis parallel to the y axis passing through the center of mass...
Definition: Polygon3d.cc:245
int getIndexOfDistalEdge(const Pos3d &) const
Return the index of the distal edge with respect to the point argument.
Definition: Polygon3d.cc:111
GEOM_FT getLength(void) const
Return the length of the object.
Definition: Polygon3d.h:59
Line in a three-dimensional space.
Definition: Line3d.h:62
GEOM_FT distSigno2(const Pos3d &p) const
Return the squared distance from from point to polygon.
Definition: Polygon3d.cc:292
virtual GEOM_FT getArea(void) const
Return the polygon area.
Definition: Polygon2d.cc:383
Pos3d Vertice0(unsigned int j) const
Return the position of the i-th vertex (0 based: j=0..getNumVertices()-1)
Definition: Polygon3d.h:72
bool intersects(const Line3d &) const
Return true if the line intersects the polygon.
Definition: Polygon3d.cc:412
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
GEOM_FT dist(const Pos3d &p) const
Return the distance from point to polygon.
Definition: Polygon3d.cc:333
Two-dimensional reference system defined in a three-dimensional space.
Definition: Ref2d3d.h:41
virtual GEOM_FT getLength(void) const
Return the perimeter of the surface.
Definition: PolygonalSurface2d.cc:90
Three-dimensional reference system defined in a three-dimensional space.
Definition: Ref3d3d.h:39
Pos3d to_3d(const Pos2d &) const
Return the 3D point corresponding to the 2D point argument.
Definition: D2to3d.cc:100