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  bool notAVector(void) const;
78  Dir3d getDirection(void) const;
79  Vector3d &operator+=(const Vector3d &);
80  Vector3d &operator-=(const Vector3d &);
81  Vector3d operator+(const Vector3d &) const;
82  Vector3d operator-(const Vector3d &) const;
83  Vector3d operator*(const GEOM_FT &) const;
84  Vector3d &operator*=(const GEOM_FT &);
85  Vector3d operator/(const GEOM_FT &) const;
86  Vector3d &operator/=(const GEOM_FT &);
87 
89  inline virtual GEOM_FT GetModulus2(void) const
90  { return (x()*x()+y()*y()+z()*z()); }
91  virtual GEOM_FT GetModulus(void) const;
92  bool EsUnitario(const double &tol= mchne_eps_dbl) const;
93  Vector3d getNormalized(void) const;
94  void Normalize(void);
95  int getIndexMaxValue(void) const;
96  int getIndexMinValue(void) const;
97  int getIndexMaxAbsValue(void) const;
98  int getIndexMinAbsValue(void) const;
99  Vector3d Normal(void) const;
100  Vector3d Perpendicular(const Vector3d &v) const;
101  virtual GEOM_FT GetDot(const Vector3d &v) const;
102  virtual GEOM_FT GetDot(const FT_matrix &m) const;
103  Vector3d getCross(const Vector3d &v) const;
104  GEOM_FT getSignedAngle(const Vector3d &v) const;
105  GEOM_FT getAngle(const Vector3d &v) const;
106  GEOM_FT getPolarAngle(void) const;
107  GEOM_FT getAzimuthalAngle(void) const;
108 
109 
110  inline friend GEOM_FT dot(const Vector3d &v1, const Vector3d &v2)
111  { return v1.GetDot(v2); }
112  inline friend GEOM_FT dot(const Vector3d &v1, const FT_matrix &m)
113  { return v1.GetDot(m); }
114  inline friend GEOM_FT dot(const FT_matrix &m, const Vector3d &v1)
115  { return v1.GetDot(m); }
116  inline friend Vector3d cross(const Vector3d &v1, const Vector3d &v2)
117  { return v1.getCross(v2); }
118  inline friend Vector3d operator^(const Vector3d &v1, const Vector3d &v2)
119  { return cross(v1,v2); }
120  friend FT_matrix operator*(const FT_matrix &m,const Vector3d &v);
121  friend std::ostream &operator<<(std::ostream &stream,const Vector3d &n);
122 
123  boost::python::dict getPyDict(void) const;
124  void setPyDict(const boost::python::dict &);
125 
126  inline virtual ~Vector3d(void) {}
127 
128  struct iterator : boost::iterator_facade<iterator, int, boost::single_pass_traversal_tag, GEOM_FT>
129  {
130  private:
131  const Vector3d *v_ptr;
132  int current_;
133  public:
134  iterator(const Vector3d *v, int i)
135  : v_ptr(v), current_(i) {}
136 
137  bool equal(iterator const& other) const
138  { return ((v_ptr==other.v_ptr) && (current_ == other.current_)); }
139  GEOM_FT dereference() const
140  { return v_ptr->at(current_); }
141  void increment()
142  { ++current_; }
143  };
144 
145  iterator begin() { return iterator(this, 0); }
146  iterator end() { return iterator(this, 2); }
147  };
148 
149 inline Vector3d operator-(const Vector3d &d)
150  {
151  Vector3d retval(d);
152  retval.Neg();
153  return retval;
154  }
155 
156 const Vector3d I_3d(1,0,0);
157 const Vector3d J_3d(0,1,0);
158 const Vector3d K_3d(0,0,1);
159 
161 inline GEOM_FT Abs2(const Vector3d &v)
162  { return v.GetModulus2(); }
163 
164 GEOM_FT Abs(const Vector3d &v); //Return the vector modulus.
165 
166 GEOM_FT signedAngle(const Vector3d &v1,const Vector3d &v2);
167 GEOM_FT angle(const Vector3d &v1,const Vector3d &v2);
168 
169 //Producto tensorial.
170 FT_matrix prod_tensor(const Vector3d &u,const Vector3d &v);
171 FT_matrix operator&(const Vector3d &u,const Vector3d &v);
172 
173 bool parallel(const Vector3d &v1,const Vector3d &v2);
174 bool coplanarios(const Vector3d &v1,const Vector3d &v2,const Vector3d &v3);
175 
176 inline Vector3d operator*(const GEOM_FT &d,const Vector3d &v)
177  { return v*d; }
178 
179 inline Vector3d normalize(const Vector3d &v)
180  { return v.getNormalized(); }
181 FT_matrix Traspuesta(const Vector3d &v);
182 FT_matrix skew_symm_matrix_post(const Vector3d &v);
183 FT_matrix skew_symm_matrix_pre(const Vector3d &v);
184 
185 const Vector3d VectorNulo3d;
186 
187 #endif
Vector3d getCross(const Vector3d &v) const
Return the cross product.
Definition: Vector3d.cc:250
Vector3d operator/(const GEOM_FT &) const
Return el producto del vector por el inverso del escalar.
Definition: Vector3d.cc:288
void Normalize(void)
Normalize vector.
Definition: Vector3d.cc:131
int getIndexMinValue(void) const
Returns the index of the maximum of the values of the components.
Definition: Vector3d.cc:154
bool notAVector(void) const
return true if one of the coordinate components is not a number.
Definition: Vector3d.cc:109
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:238
FT_matrix getMatrix(void) const
Return a column vector.
Definition: Vector3d.cc:88
int getIndexMinAbsValue(void) const
Returns the index of the maximum of the values of the components.
Definition: Vector3d.cc:190
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:274
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Vector3d.cc:462
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Vector3d.cc:452
GEOM_FT getAngle(const Vector3d &v) const
Return the angle between this vector and the argument.
Definition: Vector3d.cc:391
Base class for geometry objects.
Definition: ProtoGeom.h:33
virtual GEOM_FT GetModulus(void) const
Return el módulo del vector.
Definition: Vector3d.cc:234
virtual bool operator==(const Vector3d &) const
Comparison operator.
Definition: Vector3d.cc:66
Vector3d getNormalized(void) const
Return the normalized vector.
Definition: Vector3d.cc:122
Vector3d Perpendicular(const Vector3d &v) const
Return the vector obtained from projecting v onto the perpendicular direction to this vector...
Definition: Vector3d.cc:342
Dirección en el espacio de tres dimensiones.
Definition: Dir3d.h:35
int getIndexMaxAbsValue(void) const
Returns the index of the maximum of the values of the components.
Definition: Vector3d.cc:172
int getIndexMaxValue(void) const
Returns the index of the maximum of the values of the components.
Definition: Vector3d.cc:136
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:371
Definition: Vector3d.h:128
GEOM_FT getPolarAngle(void) const
Get the polar angle (spherical coordinates)
Definition: Vector3d.cc:415
virtual GEOM_FT GetModulus2(void) const
Return the squared modulus.
Definition: Vector3d.h:89
GEOM_FT getAzimuthalAngle(void) const
Get the azimuthal angle (spherical coordinates)
Definition: Vector3d.cc:419
Matrix which components are GEOM_FT numbers.
Definition: FT_matrix.h:40
Vector3d Normal(void) const
Return a vector perpendicular to this one.
Definition: Vector3d.cc:299
Vector3d operator+(const Vector3d &) const
Return la suma de los vectores.
Definition: Vector3d.cc:270
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:278