xc
Line3d.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 //Line3d.h
22 
23 #ifndef LINE3D_H
24 #define LINE3D_H
25 
26 #include <cstdlib>
27 #include <cmath>
28 #include "utility/utils/misc_utils/matem.h"
29 #include "Linear3d.h"
30 #include "../pos_vec/Pos3d.h"
31 #include "../pos_vec/Vector3d.h"
32 
33 
34 
36 //
39  {
40  Pos3d org;
41  Vector3d dir;
42  public:
43  Line3dParametricForm(const Pos3d &o,const Vector3d &d)
44  : org(o), dir(d) {}
45  inline const Pos3d &GetOrg(void) const
46  { return org; }
47  inline const Vector3d &GetDir(void) const
48  { return dir; }
50  inline Pos3d getPoint(const GEOM_FT &lambda) const
51  { return org+lambda*dir; }
52  };
53 
54 class Line2d;
55 class Plane;
56 class Dir3d;
57 
58 
60 //
62 class Line3d : public Linear3d
63  {
64  CGLine_3 cgr;
65  static const Pos3d defaultOrg;
66  static const Pos3d defaultDest;
67  protected:
68  void regularize(void);
69  public:
70  Line3d(void);
71  explicit Line3d(const CGLine_3 &r);
72  Line3d(const Pos3d &,const Pos3d &);
73  Line3d(const Pos3d &,const Dir3d &);
74  Line3d(const Pos3d &,const Vector3d &);
75  Line3d(const Plane &,const Plane &);
76  explicit Line3d(const Line3dParametricForm &param);
77  explicit Line3d(const GeomObj3d::list_Pos3d &lp);
78  explicit Line3d(const boost::python::list &lp);
79  virtual GeomObj *getCopy(void) const
80  { return new Line3d(*this); }
81  void swap(void);
82  void TwoPoints(const Pos3d &p1,const Pos3d &p2);
83  virtual GEOM_FT GetMax(unsigned short int) const
84  { return NAN; }
85  virtual GEOM_FT GetMin(unsigned short int i) const
86  { return NAN; }
87  const CGLine_3 &ToCGAL(void) const
88  { return cgr; }
89  inline Pos3d Point(const int &i=0) const
90  { return Pos3d(cgr.point(i)); }
91 
92  double getLambda(unsigned short int i,const double &d,const Vector3d &i_) const;
93  virtual GEOM_FT getLambda(const Pos3d &) const;
94 
95  Pos3d Projection(const Pos3d &) const;
96  Vector3d Projection(const Vector3d &) const;
97  Line3d XY3DProjection(void) const;
98  Line3d XZ3DProjection(void) const;
99  Line3d YZ3DProjection(void) const;
100 
101  Line2d XY2DProjection(void) const;
102  Line2d XZ2DProjection(void) const;
103  Line2d YZ2DProjection(void) const;
104 
105  GEOM_FT getSlope(void) const;
106  Line3dParametricForm GetParametricas(void) const;
107  Pos3d PtoParametricas(const GEOM_FT &) const;
108  void Parametricas(const Line3dParametricForm &);
110  virtual bool In(const Pos3d &p, const double &tol= 0.0) const
111  { return cgr.has_on(p.ToCGAL()); }
113  virtual GEOM_FT dist2(const Pos3d &p) const
114  { return p.dist2(Projection(p)); }
115  virtual GEOM_FT dist(const Pos3d &p) const;
116 
117  Plane Perpendicular(const Pos3d &p) const;
119  void Put(const Pos3d &p1,const Pos3d &p2)
120  { TwoPoints(p1,p2); }
121  bool isParallel(const Line3d &r) const;
122 
123  bool intersects(const Line3d &r2) const;
124  GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const;
125  GeomObj3d::list_Pos3d getIntersection(const Line3d &r2, const double &tol= sqrt_mchne_eps_dbl) const;
126 
128  inline virtual GEOM_FT getLength(void) const
129  { return NAN; }
130  inline virtual Pos3d getCenterOfMass(void) const
131  { return Pos3d(NAN,NAN,NAN); }
132  Dir3d GetDir(void) const;
133  Vector3d VDir(void) const;
134  virtual Vector3d getIVector(void) const;
135  virtual Vector3d getJVector(void) const;
136  virtual Vector3d getKVector(void) const;
137  inline double getAngle(const Vector3d &v) const
138  { return angle(VDir(),v); }
139  inline friend double angle(const Line3d &r,const Vector3d &v)
140  { return r.getAngle(v); }
141  inline friend double angle(const Line3d &r1,const Line3d &r2)
142  { return r1.getAngle(r2.VDir()); }
143 
144  GEOM_FT linearLeastSquaresFitting(const GeomObj3d::list_Pos3d &lp);
145  GEOM_FT linearLeastSquaresFittingPy(const boost::python::list &lp);
146 
149  inline virtual GEOM_FT Ix(void) const
150  { return 0.0; }
153  inline virtual GEOM_FT Iy(void) const
154  { return NAN; }
157  inline virtual GEOM_FT Iz(void) const
158  { return NAN; }
159 
160  boost::python::dict getPyDict(void) const;
161  void setPyDict(const boost::python::dict &);
162 
163  void Print(std::ostream &os) const;
164  };
165 
166 const Line3d XAxis3d(Pos3d(0,0,0),Pos3d(1,0,0));
167 const Line3d YAxis3d(Pos3d(0,0,0),Pos3d(0,1,0));
168 const Line3d ZAxis3d(Pos3d(0,0,0),Pos3d(0,0,1));
169 
170 
171 inline GEOM_FT dist2(const Pos3d &p,const Line3d &r)
172  { return r.dist2(p); }
173 inline GEOM_FT dist2(const Line3d &r,const Pos3d &p)
174  { return dist2(p,r); }
175 GEOM_FT dist(const Pos3d &p,const Line3d &r);
176 inline GEOM_FT dist(const Line3d &r,const Pos3d &p)
177  { return dist(p,r); }
178 
179 inline bool parallel(const Line3d &r1,const Line3d &r2)
180  { return r1.isParallel(r2); }
181 bool colineales(const Line3d &r1,const Line3d &r2);
182 bool coplanarias(const Line3d &r1,const Line3d &r2);
183 
184 inline bool intersecan(const Line3d &r1,const Line3d &r2)
185  { return r1.intersects(r2); }
186 inline GeomObj3d::list_Pos3d intersection(const Line3d &r1,const Line3d &r2)
187  { return r1.getIntersection(r2); }
188 
189 
190 #endif
Pos3d getPoint(const GEOM_FT &lambda) const
Return a point at a distance lambda from its origin.
Definition: Line3d.h:50
Base class for position lists.
Definition: PolyPos.h:35
virtual GEOM_FT GetMax(unsigned short int) const
Return the maximum value of the i-th coordinate.
Definition: Line3d.h:83
Line in a two-dimensional space.
Definition: Line2d.h:61
void Put(const Pos3d &p1, const Pos3d &p2)
Set the points that define the line.
Definition: Line3d.h:119
bool isParallel(const Line3d &r) const
Return true if the lines are parallel.
Definition: Line3d.cc:360
Plane in a three-dimensional space.
Definition: Plane.h:49
Vector3d VDir(void) const
Return the direction vector.
Definition: Line3d.cc:151
GeomObj3d::list_Pos3d getIntersection(unsigned short int, const double &) const
Return the intersection of the line with the plane defined by the equation coord_i= d...
Definition: Line3d.cc:417
virtual GEOM_FT getLength(void) const
Return the length of the object.
Definition: Line3d.h:128
Line in a three-dimensional space (parametric form).
Definition: Line3d.h:38
Base class for the objects involving a single dimension in a three-dimensional space.
Definition: Linear3d.h:33
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the local axis y passing through the center of mass.
Definition: Line3d.h:153
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 the point is on the line.
Definition: Line3d.h:110
Posición en tres dimensiones.
Definition: Pos3d.h:44
Line in a three-dimensional space.
Definition: Line3d.h:62
virtual GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: Line3d.h:85
bool intersects(const Line3d &r2) const
Return true if the lines intersect.
Definition: Line3d.cc:405
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the local axis x passing through the center of mass.
Definition: Line3d.h:149
virtual GEOM_FT dist2(const Pos3d &p) const
Return the squared distance from the point to the line.
Definition: Line3d.h:113
GEOM_FT dist2(const Pos3d &) const
Return the squared distance to the point.
Definition: Pos3d.cc:216
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
virtual GEOM_FT Iz(void) const
Moment of inertia with respect to the local axis z passing through the center of mass.
Definition: Line3d.h:157
Vector en tres dimensiones.
Definition: Vector3d.h:39