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 
80  GEOM_FT DistSigno(const Pos2d &p) const
81  {
82  GEOM_FT retval= lim.dist(p);
83  if(In(p)) retval= -retval;
84  return retval;
85  }
87  inline virtual GEOM_FT Dist(const Pos2d &p) const
88  { return fabs(DistSigno(p)); }
89 
90  HalfPlane2d getNormalized(void) const;
91 
92  inline bool intersects(const HalfPlane2d &r2) const
93  { return lim.intersects(r2.lim); }
94  inline bool intersects(const Line2d &r) const
95  { return lim.intersects(r); }
96  bool intersects(const Ray2d &sr) const;
97  bool intersects(const Segment2d &sg) const;
98  bool intersects(const Polyline2d &) const;
99  GeomGroup2d getIntersection(const Line2d &r) const;
100  GeomGroup2d getIntersection(const Ray2d &sr) const;
101  GeomGroup2d getIntersection(const Segment2d &sg) const;
102 
104  inline virtual GEOM_FT getLength(void) const
105  { return NAN; }
106  inline virtual Pos2d getCenterOfMass(void) const
107  { return lim.getCenterOfMass(); }
108  //Moment of inertia with respect to the center of mass in local coordinates.
109  inline virtual GEOM_FT Ix(void) const
110  { return NAN; }
111  //Moment of inertia with respect to the center of mass in local coordinates.
112  inline virtual GEOM_FT Iy(void) const
113  { return NAN; }
114  //product of inertia.
115  inline virtual GEOM_FT Pxy(void) const
116  { return NAN; }
117  //Moment of inertia with respect to the center of mass in local coordinates.
118  inline virtual GEOM_FT Iz(void) const
119  { return NAN; }
120 
121  Ray2d clip(const Line2d &) const;
122  Ray2d clip(const Ray2d &) const;
123  Segment2d clip(const Segment2d &) const;
124  std::deque<Polyline2d> clip(const Polyline2d &, const GEOM_FT &tol= 0.0) const;
125  boost::python::list clipPy(const Polyline2d &, const GEOM_FT &tol= 0.0) const;
126 
127  void Transform(const Trf2d &trf2d);
128 
129  inline void Print(std::ostream &os) const
130  { os << lim; }
131  };
132 
133 inline GEOM_FT dist(const Pos2d &p,const HalfPlane2d &r)
134  { return r.Dist(p); }
135 inline GEOM_FT dist(const HalfPlane2d &r,const Pos2d &p)
136  { return dist(p,r); }
137 inline bool operator!=(const HalfPlane2d &r1,const HalfPlane2d &r2)
138  { return !(r1==r2); }
139 
140 inline bool intersecan(const HalfPlane2d &sp1,const HalfPlane2d &sp2)
141  { return sp1.intersects(sp2); }
142 inline bool intersecan(const HalfPlane2d &sp,const Line2d &r)
143  { return sp.intersects(r); }
144 inline bool intersecan(const HalfPlane2d &sp,const Ray2d &sr)
145  { return sp.intersects(sr); }
146 inline bool intersecan(const HalfPlane2d &sp,const Segment2d &sg)
147  { return sp.intersects(sg); }
148 inline bool intersecan(const Line2d &r,const HalfPlane2d &sp)
149  { return sp.intersects(r); }
150 inline bool intersecan(const Ray2d &sr,const HalfPlane2d &sp)
151  { return sp.intersects(sr); }
152 inline bool intersecan(const Segment2d &sg,const HalfPlane2d &sp)
153  { return sp.intersects(sg); }
154 
155 GeomGroup2d intersection(const HalfPlane2d &sp,const Line2d &r);
156 GeomGroup2d intersection(const HalfPlane2d &sp,const Ray2d &sr);
157 GeomGroup2d intersection(const HalfPlane2d &sp,const Segment2d &sg);
158 GeomGroup2d intersection(const Line2d &r,const HalfPlane2d &sp);
159 GeomGroup2d intersection(const Ray2d &sr,const HalfPlane2d &sp);
160 GeomGroup2d intersection(const Segment2d &sg,const HalfPlane2d &sp);
161 
162 #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:87
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:80
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:109
Ray2d clip(const Line2d &) const
Returns the part of the line that is inside the half-space.
Definition: HalfPlane2d.cc:209
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:104
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
virtual bool operator==(const HalfPlane2d &) const
Comparison operator.
Definition: HalfPlane2d.cc:49
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:302
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
!
Definition: HalfPlane2d.h:115
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
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:323
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
virtual GEOM_FT Iz(void) const
Moment of inertia polar with respect to the center of mass en local axis.
Definition: HalfPlane2d.h:118
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 the center of mass en local axis.
Definition: HalfPlane2d.h:112
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the point is inside the half-space.
Definition: HalfPlane2d.cc:112
Ray in a two-dimensional space.
Definition: Ray2d.h:35