xc
Ray3d.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 //Ray3d.h
22 
23 #ifndef RAY3D_H
24 #define RAY3D_H
25 
26 #include "Linear3d.h"
27 #include "Line3d.h"
28 #include "../pos_vec/Pos3d.h"
29 
30 class Dir3d;
31 
32 
34 //
36 class Ray3d : public Linear3d
37  {
38  CGRay_3 cgsr;
39  public:
40  Ray3d(void);
41  explicit Ray3d(const CGRay_3 &);
42  Ray3d(const Pos3d &,const Pos3d &);
43  Ray3d(const Pos3d &,const Vector3d &);
44  virtual GeomObj *getCopy(void) const
45  { return new Ray3d(*this); }
46  void swap(void);
47  virtual bool operator==(const Ray3d &) const;
48  const CGRay_3 &ToCGAL(void) const
49  { return cgsr; }
50  void TwoPoints(const Pos3d &p1,const Pos3d &p2);
51  virtual GEOM_FT GetMax(unsigned short int) const
52  { return NAN; }
53  virtual GEOM_FT GetMin(unsigned short int) const
54  { return NAN; }
55  virtual Line3d getSupportLine(void) const
56  { return Line3d(cgsr.supporting_line()); }
57  Pos3d getFromPoint(void) const
58  { return Pos3d(cgsr.source()); }
59  inline GEOM_FT getSlope(void) const
60  { return getSupportLine().getSlope(); }
61  bool upwards(void) const;
62  bool downwards(void) const;
63  const Pos3d Point(const int &i= 0) const
64  { return Pos3d(cgsr.point(i)); }
66  Pos3d PtoParametricas(const GEOM_FT &lambda) const
67  { return Point(0)+lambda*VDir().getNormalized(); }
68  inline bool isDegenerated(void) const
69  { return cgsr.is_degenerate(); }
70  virtual bool In(const Pos3d &p, const double &tol= 0.0) const
71  //Return true if the point is on the object.
72  { return cgsr.has_on(p.ToCGAL()); }
73  virtual GEOM_FT dist2(const Pos3d &p) const;
74  GEOM_FT dist(const Pos3d &p) const;
76  void Put(const Pos3d &p1,const Pos3d &p2)
77  { TwoPoints(p1,p2); }
78 
79  bool isParallel(const Ray3d &r) const;
80  bool isParallel(const Line3d &r) const;
81 
82  GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const;
85 
86  Pos3d Projection(const Pos3d &) const;
87  Vector3d Projection(const Vector3d &) const;
88 
89  inline virtual GEOM_FT getLength(void) const
90  { return NAN; }
91  inline virtual Pos3d getCenterOfMass(void) const
92  { return Pos3d(NAN,NAN,NAN); }
93  Dir3d GetDir(void) const;
94  Vector3d VDir(void) const;
95  virtual Vector3d getIVector(void) const;
96  virtual Vector3d getJVector(void) const;
97  virtual Vector3d getKVector(void) const;
98  inline double getAngle(const Vector3d &v) const
99  { return angle(VDir(),v); }
100  //Moment of inertia with respect to the center of mass in local coordinates.
101  inline virtual GEOM_FT Ix(void) const
102  { return 0.0; }
103  //Moment of inertia with respect to the center of mass in local coordinates.
104  inline virtual GEOM_FT Iy(void) const
105  { return NAN; }
106  //Moment of inertia with respect to the center of mass in local coordinates.
107  inline virtual GEOM_FT Iz(void) const
108  { return NAN; }
109 
110  boost::python::dict getPyDict(void) const;
111  void setPyDict(const boost::python::dict &);
112 
113  inline void Print(std::ostream &os) const
114  { os << PtoParametricas(0.0) << " " << PtoParametricas(100.0); }
115  };
116 
117 inline GEOM_FT angle(const Ray3d &r,const Vector3d &v)
118  { return r.getAngle(v); }
119 inline GEOM_FT angle(const Ray3d &sr,const Line3d &r)
120  { return r.getAngle(sr.VDir()); }
121 inline GEOM_FT angle(const Line3d &r,const Ray3d &sr)
122  { return r.getAngle(sr.VDir()); }
123 
124 inline GEOM_FT dist2(const Pos3d &p,const Ray3d &r)
125  { return r.dist2(p); }
126 inline GEOM_FT dist2(const Ray3d &r,const Pos3d &p)
127  { return r.dist2(p); }
128 inline GEOM_FT dist(const Pos3d &p,const Ray3d &r)
129  { return r.dist(p); }
130 inline GEOM_FT dist(const Ray3d &r,const Pos3d &p)
131  { return r.dist(p); }
132 
133 inline bool parallel(const Ray3d &r1,const Line3d &r2)
134  { return r1.isParallel(r2); }
135 inline bool parallel(const Line3d &r1,const Ray3d &r2)
136  { return parallel(r2,r1); }
137 inline bool parallel(const Ray3d &r1,const Ray3d &r2)
138  { return r1.isParallel(r2); }
139 
140 inline GeomObj3d::list_Pos3d intersection(const Line3d &r1,const Ray3d &r2)
141  { return r2.getIntersection(r1); }
142 inline GeomObj3d::list_Pos3d intersection(const Ray3d &r1,const Line3d &r2)
143  { return r1.getIntersection(r2); }
144 inline GeomObj3d::list_Pos3d intersection(const Ray3d &r1,const Ray3d &r2)
145  { return r1.getIntersection(r2); }
146 
147 
148 inline bool colineales(const Ray3d &sr,const Line3d &r)
149  { return colineales(sr.getSupportLine(),r); }
150 inline bool colineales(const Line3d &r,const Ray3d &sr)
151  { return colineales(sr,r); }
152 inline bool colineales(const Ray3d &sr1,const Ray3d &sr2)
153  { return colineales(sr1,sr2.getSupportLine()); }
154 
155 
156 
157 #endif
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Ray3d.cc:203
void swap(void)
@ brief Swaps the ray orientation.
Definition: Ray3d.cc:80
bool downwards(void) const
Return true if the ray goes down.
Definition: Ray3d.cc:97
bool upwards(void) const
Return true if the ray goes up.
Definition: Ray3d.cc:93
Base class for position lists.
Definition: PolyPos.h:35
virtual Vector3d getKVector(void) const
Returns a vector in the direction of the local Z axis.
Definition: Ray3d.cc:112
Pos3d Projection(const Pos3d &) const
Return the orthogonal projection onto the line.
Definition: Ray3d.cc:187
virtual bool operator==(const Ray3d &) const
Comparison operator.
Definition: Ray3d.cc:65
Pos3d PtoParametricas(const GEOM_FT &lambda) const
Return a point of the line at a distance lambda from its origin.
Definition: Ray3d.h:66
GEOM_FT getSlope(void) const
Return the angle or the line with respect to XY plane.
Definition: Line3d.cc:281
Ray in a three-dimensional space.
Definition: Ray3d.h:36
Base class for the objects involving a single dimension in a three-dimensional space.
Definition: Linear3d.h:33
virtual GEOM_FT GetMin(unsigned short int) const
Return the minimum value of the i-th coordinate.
Definition: Ray3d.h:53
Vector3d getNormalized(void) const
Return the normalized vector.
Definition: Vector3d.cc:118
virtual GEOM_FT GetMax(unsigned short int) const
Return the maximum value of the i-th coordinate.
Definition: Ray3d.h:51
GEOM_FT dist(const Pos3d &p) const
Return the distance from the point to the ray.
Definition: Ray3d.cc:128
Dirección en el espacio de tres dimensiones.
Definition: Dir3d.h:35
virtual bool In(const Pos3d &p, const double &tol=0.0) const
Return true if point lies inside the object.
Definition: Ray3d.h:70
bool isParallel(const Ray3d &r) const
Return true if parallel.
Definition: Ray3d.cc:132
virtual GEOM_FT getLength(void) const
Return the object length.
Definition: Ray3d.h:89
Posición en tres dimensiones.
Definition: Pos3d.h:44
GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const
Return the intersection of the ray with the plane defined by the equation coord_i= d...
Definition: Ray3d.cc:156
Line in a three-dimensional space.
Definition: Line3d.h:62
virtual GEOM_FT dist2(const Pos3d &p) const
Returns the squared distand from the point.
Definition: Ray3d.cc:116
Ray3d(void)
Default constructor.
Definition: Ray3d.cc:30
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Ray3d.cc:212
virtual Vector3d getIVector(void) const
Returns a vector in the direction of the local X axis.
Definition: Ray3d.cc:102
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
virtual Vector3d getJVector(void) const
Returns a vector in the direction of the local Y axis.
Definition: Ray3d.cc:107
void Put(const Pos3d &p1, const Pos3d &p2)
Set the points that define the line.
Definition: Ray3d.h:76
Vector en tres dimensiones.
Definition: Vector3d.h:39