xc
Line2d.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 //Line2d.h
22 
23 #ifndef LINE2D_H
24 #define LINE2D_H
25 
26 #include "Linear2d.h"
27 #include "../pos_vec/Pos2d.h"
28 #include "../pos_vec/Vector2d.h"
29 
30 
31 
33 //
36  {
37  Pos2d org;
38  Vector2d dir;
39  public:
40  Line2dParametricForm(const Pos2d &o,const Vector2d &d)
41  : org(o), dir(d) {}
42  inline const Pos2d &GetOrg(void) const
43  { return org; }
44  inline const Vector2d &GetDir(void) const
45  { return dir; }
47  inline Pos2d getPoint(const GEOM_FT &lambda) const
48  { return org+lambda*dir; }
49  GEOM_FT Parametro(const Pos2d &p) const;
50  };
51 
52 
53 class Dir2d;
54 class Ray2d;
55 class Segment2d;
56 class Polyline2d;
57 
59 //
61 class Line2d : public Linear2d
62  {
63  CGLine_2 cgr;
64 
65  friend class Ray2d;
66  friend class Segment2d;
67  protected:
68  void regularize(void);
69  public:
70  Line2d(void);
71  explicit Line2d(const CGLine_2 &r);
72  Line2d(const Pos2d &,const Pos2d &);
73  Line2d(const Pos2d &,const Dir2d &);
74  Line2d(const Pos2d &,const Vector2d &);
75  explicit Line2d(const Line2dParametricForm &);
76  explicit Line2d(const GeomObj2d::list_Pos2d &);
77  explicit Line2d(const boost::python::list &);
78 
79  virtual bool operator==(const Line2d &) const;
80  const CGLine_2 &ToCGAL(void) const;
81  virtual GeomObj *getCopy(void) const;
82  void swap(void);
83 
84  void TwoPoints(const Pos2d &p1,const Pos2d &p2);
85  virtual GEOM_FT GetMax(unsigned short int) const
86  { return NAN; }
87  virtual GEOM_FT GetMin(unsigned short int) const
88  { return NAN; }
89 
90  Pos2d Projection(const Pos2d &p) const;
91  Vector2d Projection(const Vector2d &) const;
92  GeomObj::list_Pos2d Project(const GeomObj::list_Pos2d &ptos) const;
93 
94  GEOM_RT a(void) const;
95  GEOM_RT b(void) const;
96  GEOM_RT c(void) const;
97  GEOM_FT getSlope(void) const;
98  GEOM_FT GetParamA(void) const; //Return the parameter a (y=a*x+b) of the line.
99  GEOM_FT GetParamB(void) const; //Return the parameter a (y=a*x+b) of the line.
100 
101  GEOM_FT GetY(const GEOM_FT &x) const;
102  GEOM_FT Parametro(const Pos2d &p) const;
104  Pos2d Point(const int &i=0) const;
105 
106  double getLambda(unsigned short int i,const double &d,const Vector2d &i_) const;
107  virtual GEOM_FT getLambda(const Pos2d &) const;
108 
109  Line2dParametricForm GetParametricas(void) const;
110  Pos2d PtoParametricas(const GEOM_FT &lambda) const;
111  void Parametricas(const Line2dParametricForm &param);
112  bool EsVertical(void) const;
113  bool isDegenerated(void) const;
114  bool In(const Pos2d &p, const double &tol= 0.0) const;
115  bool negativeSide(const Pos2d &p) const;
116  bool positiveSide(const Pos2d &p) const;
117 
118  GEOM_FT dist2(const Pos2d &p) const;
119  virtual GEOM_FT dist(const Pos2d &p) const;
120 
121  Line2d Perpendicular(const Pos2d &p) const;
122  Line2d isParallel(const Pos2d &v) const;
123  Line2d offset(const Vector2d &v) const;
124  Line2d offset(const GEOM_FT &d) const;
125  void Put(const Pos2d &p1,const Pos2d &p2);
126 
127  bool intersects(const Line2d &r2) const;
129  bool intersects(const Ray2d &p) const;
130  Pos2d getIntersection(const Ray2d &p) const;
131  bool intersects(const Segment2d &p) const;
132  Pos2d getIntersection(const Segment2d &p) const;
134  GeomObj2d::list_Pos2d getIntersection(unsigned short int i, const double &d) const;
135 
136  bool isParallel(const Line2d &r) const;
137 
138  virtual GEOM_FT getLength(void) const;
139  virtual Pos2d getCenterOfMass(void) const;
140  Dir2d GetDir(void) const;
141  Vector2d VDir(void) const;
142  Vector2d Normal(void) const;
143  Vector2d VersorDir(void) const;
144  virtual Vector2d getIVector(void) const;
145  virtual Vector2d getJVector(void) const;
146  Line2d Bisectriz(const Line2d &r) const;
147  Line2d getNormalized(void) const;
148 
149  double getAngle(const Vector2d &v) const;
150  double Azimuth(void) const;
151  friend double angle(const Line2d &r,const Vector2d &v);
152  friend double angle(const Line2d &r1,const Line2d &r2);
153 
154  GEOM_FT linearLeastSquaresFitting(const GeomObj2d::list_Pos2d &lp);
155  GEOM_FT linearLeastSquaresFittingPy(const boost::python::list &lp);
156 
157  virtual GEOM_FT Ix(void) const;
158  virtual GEOM_FT Iy(void) const;
159  virtual GEOM_FT Pxy(void) const;
160  virtual GEOM_FT Iz(void) const;
161 
162  void Transform(const Trf2d &trf2d);
163 
164  boost::python::dict getPyDict(void) const;
165  void setPyDict(const boost::python::dict &);
166 
167  void Print(std::ostream &os) const;
168  void Plot(Plotter &psos) const;
169  };
170 
171 double angle(const Line2d &r,const Vector2d &v);
172 double angle(const Line2d &r1,const Line2d &r2);
173 
174 inline GEOM_FT dist2(const Pos2d &p,const Line2d &r)
175  { return r.dist2(p); }
176 inline GEOM_FT dist(const Pos2d &p,const Line2d &r)
177  { return r.dist(p); }
178 inline GEOM_FT dist2(const Line2d &r,const Pos2d &p)
179  { return dist2(p,r); }
180 inline GEOM_FT dist(const Line2d &r,const Pos2d &p)
181  { return dist(p,r); }
182 GEOM_FT dist2(const Line2d &r1,const Line2d &r2);
183 GEOM_FT dist(const Line2d &r1,const Line2d &r2);
184 
185 inline bool parallel(const Line2d &r1,const Line2d &r2)
186  { return r1.isParallel(r2); }
187 
188 bool intersecan(const Line2d &r1,const Line2d &r2);
189 GeomObj2d::list_Pos2d intersection(const Line2d &r1,const Line2d &r2);
190 Pos2d intersection_point(const Line2d &, const Line2d &);
191 
192 bool colineales(const Line2d &r1,const Line2d &r2);
193 
194 inline bool operator!=(const Line2d &r1,const Line2d &r2)
195  { return !(r1==r2); }
196 
197 inline Line2d bisectriz(const Line2d &r1,const Line2d &r2)
198  { return r1.Bisectriz(r2); }
199 Line2d perpendicular_bisector(const Pos2d &p1,const Pos2d &p2);
200 
201 #endif
202 
203 
204 
205 
Vector2d VDir(void) const
Return the direction vector of the segment.
Definition: Segment2d.cc:93
Pos2d Projection(const Pos2d &) const
Return the orthogonal projection onto the line.
Definition: Segment2d.cc:502
Pos2d getPoint(const GEOM_FT &lambda) const
Return a point at a distance lambda from its origin.
Definition: Line2d.h:47
Line2d isParallel(const Pos2d &v) const
Return the line parallel to the segment through p.
Definition: Segment2d.cc:179
virtual GEOM_FT dist(const Pos2d &p) const
Return the squared distance from the point to the line.
Definition: Line2d.cc:637
Dirección en dos dimensiones.
Definition: Dir2d.h:36
virtual GEOM_FT dist2(const Pos2d &p) const
Return the squared distance to the segment.
Definition: Segment2d.cc:260
virtual GEOM_FT Pxy(void) const
Product of inertia.
Definition: Segment2d.h:143
Base class for position lists.
Definition: PolyPos.h:35
virtual Pos2d getCenterOfMass(void) const
Return the position of the center of mass of the segment.
Definition: Segment2d.cc:166
Posición en dos dimensiones.
Definition: Pos2d.h:41
GeomObj2d::list_Pos2d getIntersection(unsigned short int, const double &) const
Return the intersection of the line with a plane defined by the equation coord_i=cte.
Definition: Segment2d.cc:309
virtual GEOM_FT getLength(void) const
Return object length.
Definition: Segment2d.cc:162
virtual GEOM_FT Iz(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Segment2d.h:146
Line in a two-dimensional space.
Definition: Line2d.h:61
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Segment2d.h:137
void Transform(const Trf2d &trf2d)
Applies to the segment the transformation argument.
Definition: Segment2d.cc:616
virtual Vector2d getJVector(void) const
Returns a vector in the direction of the local Y axis.
Definition: Segment2d.cc:111
virtual GEOM_FT GetMax(unsigned short int) const
Return the maximum value of the i-th coordinate.
Definition: Line2d.h:85
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Segment2d.h:140
Line2d Perpendicular(const Pos2d &p) const
Return the line perpendicular to the segment through p.
Definition: Segment2d.cc:175
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
Line in a two-dimensional space (parametric form).
Definition: Line2d.h:35
GEOM_FT getSlope(void) const
Return the angle or the line with respect to XY plane.
Definition: Segment2d.cc:77
Vector en dos dimensiones.
Definition: Vector2d.h:40
Dir2d GetDir(void) const
Return the direction of the segment.
Definition: Segment2d.cc:89
void swap(void)
@ brief Swaps the ray orientation.
Definition: Segment2d.cc:67
Pos2d PtoParametricas(const GEOM_FT &) const
Return a point of the segment at a distance lambda from its origin.
Definition: Segment2d.cc:285
virtual GEOM_FT GetMin(unsigned short int) const
Return the minimum value of the i-th coordinate.
Definition: Line2d.h:87
Segment in a two-dimensional space.
Definition: Segment2d.h:38
GEOM_FT Parametro(const Pos2d &p) const
Return the parameter that corresponds to the point over the line.
Definition: Line2d.cc:42
virtual Vector2d getIVector(void) const
Returns a vector in the direction of the local X axis.
Definition: Segment2d.cc:102
Segment2d offset(const Vector2d &v) const
Return the a copy of the segment translated along the vector argument.
Definition: Segment2d.cc:184
Line2d Bisectriz(const Line2d &r) const
Return the bisection line of this one an the argument line.
Definition: Line2d.cc:603
virtual GEOM_FT getLambda(const Pos2d &) const
Return the lambda parameter for the given point: p= getFromPoint()+lambda*VDir()
Definition: Linear2d.cc:29
GEOM_FT dist2(const Pos2d &p) const
Return the squared distance from the point to the line.
Definition: Line2d.cc:630
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Segment2d.cc:607
virtual bool In(const Pos2d &, const double &tol=0.0) const
Return true if the point is on the segment.
Definition: Segment2d.cc:234
virtual bool operator==(const Segment2d &) const
Comparison operator.
Definition: Segment2d.cc:52
Line2d isParallel(const Pos2d &v) const
Return a parallel line passing through p.
Definition: Line2d.cc:433
Vector2d Normal(void) const
Return the direction vector of the segment.
Definition: Segment2d.cc:97
void Put(const Pos2d &p1, const Pos2d &p2)
Set the points that define the segment.
Definition: Segment2d.h:80
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Segment2d.cc:598
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
GEOM_FT dist(const Pos2d &p) const
Return the distance from the point to the segment.
Definition: Segment2d.cc:281
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
Ray in a two-dimensional space.
Definition: Ray2d.h:35
Base class for the objects involving a single dimension in a two-dimensional space.
Definition: Linear2d.h:34
GeomObj::list_Pos2d Ordena(const GeomObj::list_Pos2d &ptos) const
Returns the points ordered by the value of the parameter of its projection onto the line from lowest ...
Definition: Segment2d.h:86
GEOM_FT getAngle(const Vector2d &v) const
Return the angle of the segment with the vector (0->2PI).
Definition: Segment2d.cc:123