xc
HalfPlane2d.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 //HalfPlane2d.h
22 
23 #ifndef HALFPLANE2D_H
24 #define HALFPLANE2D_H
25 
26 
27 #include "utility/geom/d1/Line2d.h"
28 #include "utility/geom/d2/Surface2d.h"
29 
30 class GeomGroup2d;
31 class Ray2d;
32 class Segment2d;
33 
34 
36 //
38 class HalfPlane2d : public Surface2d
39  {
40  Line2d lim; //The points of the half-plane are those we lie to the right of the line.
41  public:
42  HalfPlane2d(void);
43  explicit HalfPlane2d(const Line2d &r);
44  HalfPlane2d(const Line2d &r, const Pos2d &p);
45  HalfPlane2d(const Pos2d &p1,const Pos2d &p2);
46 
47  virtual bool operator==(const HalfPlane2d &) const;
48  virtual GeomObj *getCopy(void) const;
49  inline void swap(void);
50  HalfPlane2d getSwap(void) const;
51 
54  inline GEOM_RT a(void) const
55  { return lim.a(); }
58  inline GEOM_RT b(void) const
59  { return lim.b(); }
62  inline GEOM_RT c(void) const
63  { return lim.c(); }
64  virtual GEOM_FT GetMax(unsigned short int) const
65  { return NAN; }
66  virtual GEOM_FT GetMin(unsigned short int) const
67  { return NAN; }
68  inline bool isDegenerated(void) const
69  { return lim.isDegenerated(); }
70  inline const Line2d &getBoundaryLine(void) const
71  { return lim; }
72 
73  virtual bool In(const Pos2d &p, const double &tol= 0.0) const;
74  virtual bool In(const Line2d &, const double &tol= 0.0) const;
75  virtual bool In(const Ray2d &, const double &tol= 0.0) const;
76  virtual bool In(const Segment2d &, const double &tol= 0.0) const;
77  virtual bool In(const Polyline2d &, const double &tol= 0.0) const;
78  virtual bool In(const Polygon2d &, const double &tol= 0.0) const;
79 
80  bool Out(const Pos2d &p, const double &tol= 0.0) const;
81  bool Out(const Line2d &, const double &tol= 0.0) const;
82  bool Out(const Ray2d &, const double &tol= 0.0) const;
83  bool Out(const Segment2d &, const double &tol= 0.0) const;
84  bool Out(const Polyline2d &, const double &tol= 0.0) const;
85  bool Out(const Polygon2d &, const double &tol= 0.0) const;
86 
88  GEOM_FT DistSigno(const Pos2d &p) const
89  {
90  GEOM_FT retval= lim.dist(p);
91  if(In(p)) retval= -retval;
92  return retval;
93  }
95  inline virtual GEOM_FT Dist(const Pos2d &p) const
96  { return fabs(DistSigno(p)); }
97 
98  HalfPlane2d getNormalized(void) const;
99 
100  inline bool intersects(const HalfPlane2d &r2) const
101  { return lim.intersects(r2.lim); }
102  inline bool intersects(const Line2d &r) const
103  { return lim.intersects(r); }
104  bool intersects(const Ray2d &sr) const;
105  bool intersects(const Segment2d &sg) const;
106  bool intersects(const Polyline2d &) const;
107  GeomGroup2d getIntersection(const Line2d &r) const;
108  GeomGroup2d getIntersection(const Ray2d &sr) const;
109  GeomGroup2d getIntersection(const Segment2d &sg) const;
110 
112  inline virtual GEOM_FT getLength(void) const
113  { return NAN; }
114  inline virtual Pos2d getCenterOfMass(void) const
115  { return lim.getCenterOfMass(); }
116  //Moment of inertia with respect to the center of mass in local coordinates.
117  inline virtual GEOM_FT Ix(void) const
118  { return NAN; }
119  //Moment of inertia with respect to the center of mass in local coordinates.
120  inline virtual GEOM_FT Iy(void) const
121  { return NAN; }
122  //product of inertia.
123  inline virtual GEOM_FT Pxy(void) const
124  { return NAN; }
125  //Moment of inertia with respect to the center of mass in local coordinates.
126  inline virtual GEOM_FT Iz(void) const
127  { return NAN; }
128 
129  Ray2d clip(const Line2d &) const;
130  Ray2d clip(const Ray2d &) const;
131  Segment2d clip(const Segment2d &) const;
132  std::deque<Polyline2d> clip(const Polyline2d &, const GEOM_FT &tol= 0.0) const;
133  boost::python::list clipPy(const Polyline2d &, const GEOM_FT &tol= 0.0) const;
134  std::deque<Polygon2d> clip(const Polygon2d &) const;
135  boost::python::list clipPy(const Polygon2d &) const;
136 
137  void Transform(const Trf2d &trf2d);
138 
139  inline void Print(std::ostream &os) const
140  { os << lim; }
141  };
142 
143 inline GEOM_FT dist(const Pos2d &p,const HalfPlane2d &r)
144  { return r.Dist(p); }
145 inline GEOM_FT dist(const HalfPlane2d &r,const Pos2d &p)
146  { return dist(p,r); }
147 inline bool operator!=(const HalfPlane2d &r1,const HalfPlane2d &r2)
148  { return !(r1==r2); }
149 
150 inline bool intersecan(const HalfPlane2d &sp1,const HalfPlane2d &sp2)
151  { return sp1.intersects(sp2); }
152 inline bool intersecan(const HalfPlane2d &sp,const Line2d &r)
153  { return sp.intersects(r); }
154 inline bool intersecan(const HalfPlane2d &sp,const Ray2d &sr)
155  { return sp.intersects(sr); }
156 inline bool intersecan(const HalfPlane2d &sp,const Segment2d &sg)
157  { return sp.intersects(sg); }
158 inline bool intersecan(const Line2d &r,const HalfPlane2d &sp)
159  { return sp.intersects(r); }
160 inline bool intersecan(const Ray2d &sr,const HalfPlane2d &sp)
161  { return sp.intersects(sr); }
162 inline bool intersecan(const Segment2d &sg,const HalfPlane2d &sp)
163  { return sp.intersects(sg); }
164 
165 GeomGroup2d intersection(const HalfPlane2d &sp,const Line2d &r);
166 GeomGroup2d intersection(const HalfPlane2d &sp,const Ray2d &sr);
167 GeomGroup2d intersection(const HalfPlane2d &sp,const Segment2d &sg);
168 GeomGroup2d intersection(const Line2d &r,const HalfPlane2d &sp);
169 GeomGroup2d intersection(const Ray2d &sr,const HalfPlane2d &sp);
170 GeomGroup2d intersection(const Segment2d &sg,const HalfPlane2d &sp);
171 
172 #endif
bool intersects(const Line2d &r2) const
Return true if the line intersects the argument one.
Definition: Line2d.cc:456
virtual GEOM_FT Dist(const Pos2d &p) const
Return the distance from the point to the half-plane.
Definition: HalfPlane2d.h:95
virtual GEOM_FT dist(const Pos2d &p) const
Return the squared distance from the point to the line.
Definition: Line2d.cc:637
GEOM_FT DistSigno(const Pos2d &p) const
Return the signed distance from the point to the half-plane.
Definition: HalfPlane2d.h:88
virtual GEOM_FT GetMin(unsigned short int) const
Return the minimum value of the i-th coordinate.
Definition: HalfPlane2d.h:66
Posición en dos dimensiones.
Definition: Pos2d.h:41
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: HalfPlane2d.h:117
Ray2d clip(const Line2d &) const
Returns the part of the line that is inside the half-space.
Definition: HalfPlane2d.cc:259
Line in a two-dimensional space.
Definition: Line2d.h:61
bool isDegenerated(void) const
Return true if the line is degenerated.
Definition: Line2d.cc:614
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: HalfPlane2d.h:112
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
virtual bool operator==(const HalfPlane2d &) const
Comparison operator.
Definition: HalfPlane2d.cc:50
virtual GEOM_FT GetMax(unsigned short int) const
Return the maximum value of the i-th coordinate.
Definition: HalfPlane2d.h:64
boost::python::list clipPy(const Polyline2d &, const GEOM_FT &tol=0.0) const
Return the polyline chunks that result from clipping the given polyline with this half plane...
Definition: HalfPlane2d.cc:352
Group of 3D entities.
Definition: GeomGroup2d.h:35
GEOM_RT c(void) const
Returns the c parameter of the line equation in general form: a*x + b*y + c= 0.
Definition: Line2d.cc:260
Base class for surfaces in a two-dimensional space.
Definition: Surface2d.h:33
GEOM_RT a(void) const
Return the value of a that corresponds to the equation of the line: a*x + b*y + c= 0...
Definition: HalfPlane2d.h:54
virtual GEOM_FT Pxy(void) const
Product of inertia with respect to the center of mass.
Definition: HalfPlane2d.h:123
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
Segment in a two-dimensional space.
Definition: Segment2d.h:38
GEOM_RT a(void) const
Returns the a parameter of the line equation in general form: a*x + b*y + c= 0.
Definition: Line2d.cc:250
bool Out(const Pos2d &p, const double &tol=0.0) const
Return true if the given point is inside the half-space.
Definition: HalfPlane2d.cc:174
GEOM_RT b(void) const
Return the value of b that corresponds to the equation of the line: a*x + b*y + c= 0...
Definition: HalfPlane2d.h:58
void Transform(const Trf2d &trf2d)
Aplica al objeto la transformación que se pasa como parámetro.
Definition: HalfPlane2d.cc:387
GEOM_RT b(void) const
Returns the b parameter of the line equation in general form: a*x + b*y + c= 0.
Definition: Line2d.cc:255
Half plane in a two-dimensional space.
Definition: HalfPlane2d.h:38
GEOM_RT c(void) const
Return the value of c that corresponds to the equation of the line: a*x + b*y + c= 0...
Definition: HalfPlane2d.h:62
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
virtual Pos2d getCenterOfMass(void) const
Return the center of mass of the line.
Definition: Line2d.cc:191
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
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: HalfPlane2d.h:120
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the given point is inside the half-space.
Definition: HalfPlane2d.cc:113
Ray in a two-dimensional space.
Definition: Ray2d.h:35