xc
Vector3d.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 //Vector3d.h
22 
23 #ifndef VECTOR3D_H
24 #define VECTOR3D_H
25 
26 #include "utility/utils/misc_utils/mchne_eps.h"
27 #include "../ProtoGeom.h"
28 #include "../cgal_types.h"
29 
30 class Pos3d;
31 class Dir3d;
32 class FT_matrix;
33 class SbVec3f;
34 
35 
37 //
39 class Vector3d: public ProtoGeom
40  {
41  CGVector_3 cgvct;
42  public:
43  Vector3d(void): cgvct(CGAL::NULL_VECTOR){}
44  explicit Vector3d(const CGVector_3 &v)
45  : cgvct(v) {}
46  Vector3d(const GEOM_FT &x,const GEOM_FT &y,const GEOM_FT &z);
47  explicit Vector3d(const FT_matrix &m);
48  explicit Vector3d(const boost::python::list &);
49  Vector3d(const Pos3d &p1,const Pos3d &p2);
50  virtual bool operator==(const Vector3d &) const;
51  bool operator!=(const Vector3d &) const;
52  const CGVector_3 &ToCGAL(void) const
53  { return cgvct; }
54  inline int dimension(void) const
55  { return cgvct.dimension(); }
56  void Neg(void)
57  { cgvct= -cgvct; }
58  bool Nulo(void) const;
59  void SetX(const GEOM_FT &vx);
60  void SetY(const GEOM_FT &vy);
61  void SetZ(const GEOM_FT &vz);
62  void Set(unsigned short int i,const GEOM_FT &v);
63  inline GEOM_FT at(const size_t &i) const
64  { return cgvct.cartesian(i); }
65  inline GEOM_FT operator()(const size_t &i) const //Base 1.
66  { return at(i-1); }
67  inline GEOM_FT operator[](const size_t &i) const //Base 0.
68  { return at(i); }
69  inline GEOM_FT x(void) const
70  { return cgvct.x(); }
71  inline GEOM_FT y(void) const
72  { return cgvct.y(); }
73  inline GEOM_FT z(void) const
74  { return cgvct.z(); }
75  FT_matrix getMatrix(void) const;
76  boost::python::list getPyList(void) const;
77  Dir3d getDirection(void) const;
78  Vector3d &operator+=(const Vector3d &);
79  Vector3d &operator-=(const Vector3d &);
80  Vector3d operator+(const Vector3d &) const;
81  Vector3d operator-(const Vector3d &) const;
82  Vector3d operator*(const GEOM_FT &) const;
83  Vector3d operator/(const GEOM_FT &) const;
84 
86  inline virtual GEOM_FT GetModulus2(void) const
87  { return (x()*x()+y()*y()+z()*z()); }
88  virtual GEOM_FT GetModulus(void) const;
89  bool EsUnitario(const double &tol= mchne_eps_dbl) const;
90  Vector3d getNormalized(void) const;
91  void Normalize(void);
92  Vector3d Perpendicular(const Vector3d &v) const;
93  virtual GEOM_FT GetDot(const Vector3d &v) const;
94  virtual GEOM_FT GetDot(const FT_matrix &m) const;
95  Vector3d getCross(const Vector3d &v) const;
96  GEOM_FT getSignedAngle(const Vector3d &v) const;
97  GEOM_FT getAngle(const Vector3d &v) const;
98  GEOM_FT getPolarAngle(void) const;
99  GEOM_FT getAzimuthalAngle(void) const;
100 
101 
102  inline friend GEOM_FT dot(const Vector3d &v1, const Vector3d &v2)
103  { return v1.GetDot(v2); }
104  inline friend GEOM_FT dot(const Vector3d &v1, const FT_matrix &m)
105  { return v1.GetDot(m); }
106  inline friend GEOM_FT dot(const FT_matrix &m, const Vector3d &v1)
107  { return v1.GetDot(m); }
108  inline friend Vector3d cross(const Vector3d &v1, const Vector3d &v2)
109  { return v1.getCross(v2); }
110  inline friend Vector3d operator^(const Vector3d &v1, const Vector3d &v2)
111  { return cross(v1,v2); }
112  friend FT_matrix operator*(const FT_matrix &m,const Vector3d &v);
113  friend std::ostream &operator<<(std::ostream &stream,const Vector3d &n);
114 
115  boost::python::dict getPyDict(void) const;
116  void setPyDict(const boost::python::dict &);
117 
118  inline virtual ~Vector3d(void) {}
119  };
120 
121 inline Vector3d operator-(const Vector3d &d)
122  {
123  Vector3d retval(d);
124  retval.Neg();
125  return retval;
126  }
127 
128 const Vector3d I_3d(1,0,0);
129 const Vector3d J_3d(0,1,0);
130 const Vector3d K_3d(0,0,1);
131 
133 inline GEOM_FT Abs2(const Vector3d &v)
134  { return v.GetModulus2(); }
135 
136 GEOM_FT Abs(const Vector3d &v); //Return the vector modulus.
137 
138 GEOM_FT signedAngle(const Vector3d &v1,const Vector3d &v2);
139 GEOM_FT angle(const Vector3d &v1,const Vector3d &v2);
140 
141 //Producto tensorial.
142 FT_matrix prod_tensor(const Vector3d &u,const Vector3d &v);
143 FT_matrix operator&(const Vector3d &u,const Vector3d &v);
144 
145 bool parallel(const Vector3d &v1,const Vector3d &v2);
146 bool coplanarios(const Vector3d &v1,const Vector3d &v2,const Vector3d &v3);
147 
148 inline Vector3d operator*(const GEOM_FT &d,const Vector3d &v)
149  { return v*d; }
150 
151 inline Vector3d normalize(const Vector3d &v)
152  { return v.getNormalized(); }
153 FT_matrix Traspuesta(const Vector3d &v);
154 FT_matrix skew_symm_matrix_post(const Vector3d &v);
155 FT_matrix skew_symm_matrix_pre(const Vector3d &v);
156 
157 const Vector3d VectorNulo3d;
158 
159 #endif
Vector3d getCross(const Vector3d &v) const
Return the cross product.
Definition: Vector3d.cc:174
Vector3d operator/(const GEOM_FT &) const
Return el producto del vector por el inverso del escalar.
Definition: Vector3d.cc:206
void Normalize(void)
Normalize vector.
Definition: Vector3d.cc:127
boost::python::list getPyList(void) const
Return the point coordinates in a Python list.
Definition: Vector3d.cc:96
virtual GEOM_FT GetDot(const Vector3d &v) const
Return el producto escalar.
Definition: Vector3d.cc:162
FT_matrix getMatrix(void) const
Return a column vector.
Definition: Vector3d.cc:88
bool operator!=(const Vector3d &) const
Comparison operator.
Definition: Vector3d.cc:81
Vector3d operator-(const Vector3d &) const
Return la resta de los vectores.
Definition: Vector3d.cc:198
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Vector3d.cc:330
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Vector3d.cc:320
GEOM_FT getAngle(const Vector3d &v) const
Return the angle between this vector and the argument.
Definition: Vector3d.cc:261
Base class for geometry objects.
Definition: ProtoGeom.h:33
virtual GEOM_FT GetModulus(void) const
Return el módulo del vector.
Definition: Vector3d.cc:158
virtual bool operator==(const Vector3d &) const
Comparison operator.
Definition: Vector3d.cc:66
Vector3d getNormalized(void) const
Return the normalized vector.
Definition: Vector3d.cc:118
Vector3d Perpendicular(const Vector3d &v) const
Return the vector obtained from projecting v onto the perpendicular direction to this vector...
Definition: Vector3d.cc:212
Dirección en el espacio de tres dimensiones.
Definition: Dir3d.h:35
Posición en tres dimensiones.
Definition: Pos3d.h:44
GEOM_FT getSignedAngle(const Vector3d &v) const
Return the angle between this vector and the argument.
Definition: Vector3d.cc:241
GEOM_FT getPolarAngle(void) const
Get the polar angle (spherical coordinates)
Definition: Vector3d.cc:285
virtual GEOM_FT GetModulus2(void) const
Return the squared modulus.
Definition: Vector3d.h:86
GEOM_FT getAzimuthalAngle(void) const
Get the azimuthal angle (spherical coordinates)
Definition: Vector3d.cc:289
Matrix which components are GEOM_FT numbers.
Definition: FT_matrix.h:40
Vector3d operator+(const Vector3d &) const
Return la suma de los vectores.
Definition: Vector3d.cc:194
Vector en tres dimensiones.
Definition: Vector3d.h:39
Vector3d operator*(const GEOM_FT &) const
Return el producto del vector por el escalar.
Definition: Vector3d.cc:202