xc
Ray2d.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 //Ray2d.h
22 
23 #ifndef RAY2D_H
24 #define RAY2D_H
25 
26 #include "Linear2d.h"
27 #include "Line2d.h"
28 #include "../pos_vec/Pos2d.h"
29 
30 class Dir2d;
31 
33 //
35 class Ray2d : public Linear2d
36  {
37  CGRay_2 cgsr;
38 
39  friend class Segment2d;
40  public:
41  Ray2d(void): Linear2d(),cgsr(CGPoint_2(0,0),CGPoint_2(1,0)) {}
42  explicit Ray2d(const CGRay_2 &r)
43  : Linear2d(), cgsr(r) {}
44  Ray2d(const Pos2d &p1,const Pos2d &p2);
45  Ray2d(const Pos2d &p1,const Vector2d &vdir);
46 
47  virtual bool operator==(const Ray2d &) const;
48  const CGRay_2 &ToCGAL(void) const
49  { return cgsr; }
50  virtual GeomObj *getCopy(void) const
51  { return new Ray2d(*this); }
52  void swap(void);
53  void TwoPoints(const Pos2d &p1,const Pos2d &p2);
54  virtual GEOM_FT GetMax(unsigned short int) const
55  { return NAN; }
56  virtual GEOM_FT GetMin(unsigned short int) const
57  { return NAN; }
58  virtual Line2d getSupportLine(void) const
59  { return Line2d(cgsr.supporting_line()); }
60  Pos2d getFromPoint(void) const
61  { return Pos2d(cgsr.source()); }
62  inline GEOM_FT getSlope(void) const
63  { return getSupportLine().getSlope(); }
64  bool upwards(void) const;
65  bool downwards(void) const;
66  const Pos2d Point(const int &i) const
67  { return Pos2d(cgsr.point(i)); }
68  Pos2d PtoParametricas(const GEOM_FT &) const;
69  inline bool EsVertical(void) const
70  { return cgsr.is_vertical(); }
71  inline bool isDegenerated(void) const
72  { return cgsr.is_degenerate(); }
73  //@brief Return true if the points is on the ray.
74  virtual bool In(const Pos2d &p, const double &tol= 0.0) const
75  { return cgsr.has_on(p.ToCGAL()); }
76  GEOM_FT dist2(const Pos2d &p) const;
77  GEOM_FT dist(const Pos2d &p) const;
79  void Put(const Pos2d &p1,const Pos2d &p2)
80  { TwoPoints(p1,p2); }
81 
86  { return getSupportLine().Ordena(ptos); }
87 
88  bool intersects(const Ray2d &sr2) const
89  { return do_intersect(cgsr,sr2.cgsr); }
90  bool intersects(const Line2d &sr) const;
91  GeomObj2d::list_Pos2d getIntersection(unsigned short int, const double &) const;
94 
95  Pos2d Projection(const Pos2d &) const;
96  Vector2d Projection(const Vector2d &) const;
97 
98  bool isParallel(const Line2d &r) const
99  { return parallel(getSupportLine(),r); }
100  bool isParallel(const Ray2d &sr) const
101  { return isParallel(sr.getSupportLine()); }
102 
104  inline virtual GEOM_FT getLength(void) const
105  { return NAN; }
106  inline virtual Pos2d getCenterOfMass(void) const
107  { return Pos2d(NAN,NAN); }
108  Dir2d GetDir(void) const;
109  Vector2d VDir(void) const;
110  Vector2d Normal(void) const;
111  virtual Vector2d getIVector(void) const;
112  virtual Vector2d getJVector(void) const;
113  inline GEOM_FT getAngle(const Vector2d &v) const
114  { return angle(VDir(),v); }
115  inline friend GEOM_FT angle(const Ray2d &r,const Vector2d &v)
116  { return r.getAngle(v); }
117  //Moment of inertia with respect to the center of mass in local coordinates.
118  inline virtual GEOM_FT Ix(void) const
119  { return 0.0; }
120  //Moment of inertia with respect to the center of mass in local coordinates.
121  inline virtual GEOM_FT Iy(void) const
122  { return NAN; }
123  //product of inertia.
124  inline virtual GEOM_FT Pxy(void) const
125  { return NAN; }
126  //Moment of inertia with respect to the center of mass in local coordinates.
127  inline virtual GEOM_FT Iz(void) const
128  { return NAN; }
129 
130  void Transform(const Trf2d &trf2d);
131 
132  boost::python::dict getPyDict(void) const;
133  void setPyDict(const boost::python::dict &);
134 
135  void Print(std::ostream &os) const;
136  void Plot(Plotter &psos) const;
137  };
138 
139 inline GEOM_FT dist2(const Pos2d &p,const Ray2d &r)
140  { return r.dist2(p); }
141 inline GEOM_FT dist2(const Ray2d &r,const Pos2d &p)
142  { return dist2(p,r); }
143 inline GEOM_FT dist(const Pos2d &p,const Ray2d &r)
144  { return r.dist(p); }
145 inline GEOM_FT dist(const Ray2d &r,const Pos2d &p)
146  { return dist(p,r); }
147 
148 inline bool parallel(const Ray2d &sr,const Line2d &r)
149  { return sr.isParallel(r); }
150 inline bool parallel(const Line2d &r,const Ray2d &sr)
151  { return parallel(sr,r); }
152 inline bool parallel(const Ray2d &r1,const Ray2d &r2)
153  { return r1.isParallel(r2); }
154 
155 inline bool intersecan(const Ray2d &sr1,const Ray2d &sr2)
156  { return sr1.intersects(sr2); }
157 inline bool intersecan(const Ray2d &sr,const Line2d &r)
158  { return sr.intersects(r); }
159 inline bool intersecan(const Line2d &r,const Ray2d &sr)
160  { return sr.intersects(r); }
161 inline GeomObj2d::list_Pos2d intersection(const Ray2d &sr,const Line2d &r)
162  { return sr.getIntersection(r); }
163 inline GeomObj2d::list_Pos2d intersection(const Line2d &r, const Ray2d &sr)
164  { return sr.getIntersection(r); }
165 
168 inline GeomObj2d::list_Pos2d intersection(const Ray2d &sr1,const Ray2d &sr2)
169  { return sr1.getIntersection(sr2); }
170 
171 
172 inline bool colineales(const Ray2d &sr,const Line2d &r)
173  { return colineales(sr.getSupportLine(),r); }
174 inline bool colineales(const Line2d &r,const Ray2d &sr)
175  { return colineales(sr,r); }
176 inline bool colineales(const Ray2d &sr1,const Ray2d &sr2)
177  { return colineales(sr1,sr2.getSupportLine()); }
178 
179 
180 #endif
Pos2d Projection(const Pos2d &) const
Return the orthogonal projection onto the line.
Definition: Ray2d.cc:205
Vector2d VDir(void) const
Return the direction vector of the segment.
Definition: Segment2d.cc:93
void Transform(const Trf2d &trf2d)
Applies to the ray the transformation argument.
Definition: Ray2d.cc:220
void Put(const Pos2d &p1, const Pos2d &p2)
Set the points that define the ray.
Definition: Ray2d.h:79
Line2d isParallel(const Pos2d &v) const
Return the line parallel to the segment through p.
Definition: Segment2d.cc:179
Dirección en dos dimensiones.
Definition: Dir2d.h:36
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Ray2d.h:121
GeomObj2d::list_Pos2d getIntersection(unsigned short int, const double &) const
Return the intersection of the ray with the plane defined by the equation coord_i= d...
Definition: Ray2d.cc:137
Pos2d PtoParametricas(const GEOM_FT &) const
Return a point of the line at a distance lambda from its origin.
Definition: Ray2d.cc:104
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
Vector2d Normal(void) const
Return the direction vector of the segment.
Definition: Ray2d.cc:73
Posición en dos dimensiones.
Definition: Pos2d.h:41
Line in a two-dimensional space.
Definition: Line2d.h:61
virtual GEOM_FT GetMin(unsigned short int) const
Return the minimum value of the i-th coordinate.
Definition: Ray2d.h:56
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: Ray2d.h:85
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Ray2d.cc:237
void swap(void)
@ brief Swaps the ray orientation.
Definition: Ray2d.cc:60
GEOM_FT dist(const Pos2d &p) const
Return the distance from the point to the ray.
Definition: Ray2d.cc:129
virtual bool In(const Pos2d &p, const double &tol=0.0) const
Return true if the point lies inside the object.
Definition: Ray2d.h:74
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
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
virtual Vector2d getJVector(void) const
Returns a vector in the direction of the local Y axis.
Definition: Ray2d.cc:95
virtual Vector2d getIVector(void) const
Returns a vector in the direction of the local X axis.
Definition: Ray2d.cc:86
Segment in a two-dimensional space.
Definition: Segment2d.h:38
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Ray2d.cc:228
bool downwards(void) const
Return true if the ray goes down.
Definition: Ray2d.cc:81
virtual GEOM_FT Pxy(void) const
!
Definition: Ray2d.h:124
GeomObj::list_Pos2d Ordena(const GeomObj::list_Pos2d &ptos) const
Return the points ordered by the value of the parameter of its projection onto the line from lowest t...
Definition: Line2d.cc:380
GEOM_FT getSlope(void) const
Return the slope of the line.
Definition: Line2d.cc:264
GEOM_FT dist2(const Pos2d &p) const
Return the squared distance from the point to the ray.
Definition: Ray2d.cc:114
virtual GEOM_FT Iz(void) const
Moment of inertia polar with respect to the center of mass en local axis.
Definition: Ray2d.h:127
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: Ray2d.h:118
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: Ray2d.h:104
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
virtual bool operator==(const Ray2d &) const
Comparison operator.
Definition: Ray2d.cc:45
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
virtual GEOM_FT GetMax(unsigned short int) const
Return the maximum value of the i-th coordinate.
Definition: Ray2d.h:54
bool upwards(void) const
Return true if the ray goes up.
Definition: Ray2d.cc:77
GEOM_FT getAngle(const Vector2d &v) const
Return the angle of the segment with the vector (0->2PI).
Definition: Segment2d.cc:123