xc
Pos3d.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 //Pos3d.h
22 
23 #ifndef POS3D_H
24 #define POS3D_H
25 
26 
27 #include <iostream>
28 #include <string>
29 #include "../cgal_types.h"
30 #include "../ProtoGeom.h"
31 
32 class Vector3d;
33 class Pos2d;
34 class Line3d;
35 class Ray3d;
36 class Segment3d;
37 class Plane;
38 class HalfSpace3d;
39 class Solid3d;
40 
42 //
44 class Pos3d : public ProtoGeom
45  {
46  CGPoint_3 cgpt;
47  public:
48  typedef Vector3d vector;
49  typedef CGPoint_3::Cartesian_const_iterator Cartesian_const_iterator;
50 
51  Pos3d(void)
52  : ProtoGeom(), cgpt(CGAL::ORIGIN) {}
53  Pos3d(const CGPoint_3 &p)
54  : ProtoGeom(), cgpt(p) {}
55  Pos3d(const GEOM_FT &Ax,const GEOM_FT &Ay,const GEOM_FT &Az)
56  : ProtoGeom(), cgpt(Ax,Ay,Az) {}
57 /* Pos3d(const double &Ax,const double &Ay,const double &Az) */
58 /* : ProtoGeom(), cgpt(Point_3_from_doubles(Ax,Ay,Az)) {} */
59 
60  bool notAPoint(void) const;
61  Pos3d &operator+=(const Vector3d &);
62  Pos3d &operator-=(const Vector3d &);
63  Vector3d operator-(const Pos3d &) const;
64  Pos3d operator-(const Vector3d &) const;
65  Pos3d operator+(const Vector3d &) const;
66  virtual bool operator==(const Pos3d &) const;
67  inline bool operator!=(const Pos3d &other) const
68  { return !(*this==other); }
69  const CGPoint_3 &ToCGAL(void) const
70  { return cgpt; }
71  GEOM_FT at0(const size_t &i) const;
72  GEOM_FT operator()(const size_t &i) const;
73  inline GEOM_FT operator[](const size_t &j) const //Base 0
74  { return at0(j); }
75  inline const GEOM_FT x() const
76  { return Pos3d::operator()(1); }
77  inline const GEOM_FT y() const
78  { return Pos3d::operator()(2); }
79  inline const GEOM_FT z() const
80  { return Pos3d::operator()(3); }
81  inline const GEOM_RT hx() const
82  { return cgpt.hx(); }
83  inline const GEOM_RT hy() const
84  { return cgpt.hy(); }
85  inline const GEOM_RT hz() const
86  { return cgpt.hz(); }
87  inline const GEOM_RT hw() const
88  { return cgpt.hw(); }
89 
90  void SetX(const GEOM_FT &vx);
91  void SetY(const GEOM_FT &vy);
92  void SetZ(const GEOM_FT &vz);
93  void Set(unsigned short int i,const GEOM_FT &v);
94 
95  inline Cartesian_const_iterator cartesian_begin(void) const
96  { return ToCGAL().cartesian_begin(); }
97  inline Cartesian_const_iterator cartesian_end(void) const
98  { return ToCGAL().cartesian_end(); }
99  size_t dimension(void) const
100  { return cgpt.dimension(); }
101  Vector3d VectorPos(void) const;
102  bool domina_a(const Pos3d &b) const;
103 
104  GEOM_FT dist(const Pos3d &) const;
105  GEOM_FT dist2(const Pos3d &) const;
106  GEOM_FT dist2(const Line3d &) const;
107  GEOM_FT dist(const Line3d &) const;
108  GEOM_FT dist2(const Ray3d &) const;
109  GEOM_FT dist(const Ray3d &) const;
110  GEOM_FT dist2(const Segment3d &) const;
111  GEOM_FT dist(const Segment3d &) const;
112  GEOM_FT dist2(const Plane &) const;
113  GEOM_FT dist(const Plane &) const;
114  GEOM_FT dist2(const HalfSpace3d &) const;
115  GEOM_FT dist(const HalfSpace3d &) const;
116  GEOM_FT dist(const Solid3d &) const;
117 
118  int Cuadrante(void) const;
119 
120  Pos3d XY3DProjection(void) const; //Return projection onto XY plane.
121  Pos3d XZ3DProjection(void) const; //Return projection onto XZ plane.
122  Pos3d YZ3DProjection(void) const; //Return projection onto YZ plane.
123 
124  Pos2d XY2DProjection(void) const; //Return projection onto XY plane.
125  Pos2d XZ2DProjection(void) const; //Return projection onto XZ plane.
126  Pos2d YZ2DProjection(void) const; //Return projection onto YZ plane.
127 
128  Pos3d getModArgX(const GEOM_FT &mod,const GEOM_FT &giroX) const;
129  Pos3d getModArgY(const GEOM_FT &mod,const GEOM_FT &giroY) const;
130  Pos3d getModArgZ(const GEOM_FT &mod,const GEOM_FT &giroZ) const;
131 
132  friend bool colineales(const Pos3d &p1,const Pos3d &p2,const Pos3d &p3);
133  friend bool coplanarios(const Pos3d &p1,const Pos3d &p2,const Pos3d &p3,const Pos3d &p4);
134  friend std::ostream &operator<<(std::ostream &stream,const Pos3d &n);
135 
136  boost::python::dict getPyDict(void) const;
137  void setPyDict(const boost::python::dict &);
138  };
139 
140 Pos3d To3dXY2d(const Pos2d &p,const GEOM_FT &z= 0);
141 Pos3d To3dXZ2d(const Pos2d &p,const GEOM_FT &y= 0);
142 Pos3d To3dYZ2d(const Pos2d &p,const GEOM_FT &x= 0);
143 Pos3d To3d(const Pos2d &p,const size_t &coo,const GEOM_FT &u=0);
144 
145 
146 inline GEOM_FT dist2(const Pos3d &p1,const Pos3d &p2)
147  { return p1.dist2(p2); }
148 
149 inline GEOM_FT dist(const Pos3d &p1,const Pos3d &p2)
150  { return p1.dist(p2); }
151 
152 inline Pos3d pos_max(const Pos3d &a,const Pos3d &b)
153  { return Pos3d(std::max(a.x(),b.x()),std::max(a.y(),b.y()),std::max(a.z(),b.z())); }
154 inline Pos3d pos_min(const Pos3d &a,const Pos3d &b)
155  { return Pos3d(std::min(a.x(),b.x()),std::min(a.y(),b.y()),std::min(a.z(),b.z())); }
156 
157 const Pos3d Origin3d;
158 
159 #endif
Pos3d YZ3DProjection(void) const
Return the projection onto YZ plane.
Definition: Pos3d.cc:165
Segment en tres dimensiones.
Definition: Segment3d.h:41
Posición en dos dimensiones.
Definition: Pos2d.h:41
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Pos3d.cc:308
int Cuadrante(void) const
Return the quadrant of the point.
Definition: Pos3d.cc:129
Vector3d operator-(const Pos3d &) const
Vector between the points.
Definition: Pos3d.cc:57
Pos2d XY2DProjection(void) const
Return the projection onto XY plane.
Definition: Pos3d.cc:169
Pos3d & operator-=(const Vector3d &)
Substracts a vector.
Definition: Pos3d.cc:50
Plane in a three-dimensional space.
Definition: Plane.h:49
Clase base para los sólidos en tres dimensiones.
Definition: Solid3d.h:31
Pos3d getModArgY(const GEOM_FT &mod, const GEOM_FT &giroY) const
Equivalent to the <arg command from Autocad <arg Rotation with respect to the y axis.
Definition: Pos3d.cc:195
Vector3d VectorPos(void) const
Return the position vector of the point.
Definition: Pos3d.cc:93
Pos3d operator+(const Vector3d &) const
Point obtained by addition of the vector.
Definition: Pos3d.cc:71
ProtoGeom(void)
False when solution is not possible: intersection of parallel planes.
Definition: ProtoGeom.cc:33
Ray in a three-dimensional space.
Definition: Ray3d.h:36
Base class for geometry objects.
Definition: ProtoGeom.h:33
Pos3d & operator+=(const Vector3d &)
Adds a vector.
Definition: Pos3d.cc:43
Pos2d XZ2DProjection(void) const
Return the projection onto XZ plane.
Definition: Pos3d.cc:175
Pos2d YZ2DProjection(void) const
Return the projection onto YZ plane.
Definition: Pos3d.cc:182
Pos3d XY3DProjection(void) const
Return the projection onto XY plane.
Definition: Pos3d.cc:159
GEOM_FT dist(const Pos3d &) const
Return the distance to the point.
Definition: Pos3d.cc:212
friend bool colineales(const Pos3d &p1, const Pos3d &p2, const Pos3d &p3)
Return true if the points are collinear.
Definition: Pos3d.cc:290
Posición en tres dimensiones.
Definition: Pos3d.h:44
Line in a three-dimensional space.
Definition: Line3d.h:62
bool notAPoint(void) const
return true if one of the coordinate components is not a number.
Definition: Pos3d.cc:38
friend bool coplanarios(const Pos3d &p1, const Pos3d &p2, const Pos3d &p3, const Pos3d &p4)
Return true if the points are coplanar.
Definition: Pos3d.cc:294
virtual bool operator==(const Pos3d &) const
Comparison operator.
Definition: Pos3d.cc:78
Pos3d getModArgZ(const GEOM_FT &mod, const GEOM_FT &giroZ) const
Equivalent to the <arg command from Autocad <arg Rotation with respect to the z axis.
Definition: Pos3d.cc:201
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Pos3d.cc:298
GEOM_FT dist2(const Pos3d &) const
Return the squared distance to the point.
Definition: Pos3d.cc:216
The points of the half space are those that line at the back of the plane, this being understood as t...
Definition: HalfSpace3d.h:42
Vector en tres dimensiones.
Definition: Vector3d.h:39
Pos3d getModArgX(const GEOM_FT &mod, const GEOM_FT &giroX) const
Equivalent to the <arg command from Autocad <arg Rotation with respect to the x axis.
Definition: Pos3d.cc:190
Pos3d XZ3DProjection(void) const
Return the projection onto XZ plane.
Definition: Pos3d.cc:162