xc
Vector2d.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 //Vector2d.h
22 
23 #ifndef VECTOR2D_H
24 #define VECTOR2D_H
25 
26 #include "utility/utils/misc_utils/mchne_eps.h"
27 #include "utility/matrices/op_tensor.h"
28 #include "../cgal_types.h"
29 #include "../ProtoGeom.h"
30 
31 class Pos2d;
32 class Dir2d;
33 class Plotter;
34 class FT_matrix;
35 
36 
38 //
40 class Vector2d: public ProtoGeom
41  {
42  CGVector_2 cgvct;
43  public:
44  Vector2d(void): ProtoGeom(), cgvct(CGAL::NULL_VECTOR) {}
45  explicit Vector2d(const CGVector_2 &v)
46  : ProtoGeom(), cgvct(v) {}
47  explicit Vector2d(const CGDirection_2 &dir)
48  : ProtoGeom(), cgvct(dir.vector()) {}
49  Vector2d(const GEOM_FT &x,const GEOM_FT &y);
50  explicit Vector2d(const boost::python::list &);
51 /* Vector2d(const double &x,const double &y); */
52  explicit Vector2d(const FT_matrix &m);
53  Vector2d(const Pos2d &p1,const Pos2d &p2);
54 
55  virtual bool operator==(const Vector2d &) const;
56  bool operator!=(const Vector2d &) const;
57  const CGVector_2 &ToCGAL(void) const
58  { return cgvct; }
59  inline int dimension(void) const
60  { return cgvct.dimension(); }
61  void Neg(void)
62  { cgvct= -cgvct; }
63  inline Vector2d operator-(void) const
64  {
65  Vector2d retval(*this);
66  retval.Neg();
67  return retval;
68  }
69  bool Nulo(void) const;
70  void SetX(const GEOM_FT &vx);
71  void SetY(const GEOM_FT &vy);
72  void Set(unsigned short int i,const GEOM_FT &v);
73 
74  inline GEOM_FT at(const size_t &i) const
75  { return cgvct.cartesian(i); }
76  inline GEOM_FT operator()(const size_t &i) const //Base 1.
77  { return at(i-1); }
78  inline GEOM_FT operator[](const size_t &j) const //Base 0.
79  { return at(j); }
80  inline GEOM_FT x() const
81  { return Vector2d::operator()(1); }
82  inline GEOM_FT y() const
83  { return Vector2d::operator()(2); }
84  FT_matrix getMatrix(void) const;
85  boost::python::list getPyList(void) const;
86  Vector2d &operator+=(const Vector2d &);
87  Vector2d &operator-=(const Vector2d &);
88  Vector2d operator+(const Vector2d &) const;
89  Vector2d operator-(const Vector2d &) const;
90  Vector2d operator*(const GEOM_FT &) const;
91  Vector2d operator/(const GEOM_FT &) const;
92 
93  inline virtual GEOM_FT GetModulus2(void) const
94  { return (x()*x()+y()*y()); }
95  virtual GEOM_FT GetModulus(void) const;
96  bool EsUnitario(const double &tol= mchne_eps_dbl) const;
97 
99  inline Vector2d getNormalized(void) const
100  { return (*this)/GetModulus(); }
101  void Normalize(void);
102  Vector2d Normal(void) const;
103  Dir2d getDirection(void) const;
104  GEOM_FT getSignedAngle(const Vector2d &v) const;
105  GEOM_FT getAngle(const Vector2d &v) const;
106  GEOM_FT XAxisAngle(void) const;
107  GEOM_FT YAxisAngle(void) const;
108 
109  //Producto escalar.
110  inline virtual GEOM_FT GetDot(const Vector2d &v) const
111  { return (x()*v.x()+y()*v.y()); }
112  virtual GEOM_FT GetDot(const FT_matrix &m) const;
113  inline friend GEOM_FT dot(const Vector2d &v1, const Vector2d &v2)
114  { return v1.GetDot(v2); }
115  friend GEOM_FT dot(const Vector2d &v1, const FT_matrix &m);
116  friend GEOM_FT dot(const FT_matrix &m, const Vector2d &v1);
117 
118  friend FT_matrix operator*(const FT_matrix &m,const Vector2d &v);
119 
120  //void Rotate(const GEOM_FT &ang_rad);
121  Vector2d Rotated(const double &ang_rad) const;
122  Vector2d Perpendicular(const Orientacion &o) const;
123  Vector2d Perpendicular(const Vector2d &v) const;
124 
125  boost::python::dict getPyDict(void) const;
126  void setPyDict(const boost::python::dict &);
127 
128  void Print(std::ostream &stream) const;
129  void Plot(Plotter &psos) const;
130  friend std::ostream &operator<<(std::ostream &stream,const Vector2d &n);
131  inline virtual ~Vector2d(void) {}
132  };
133 
134 inline GEOM_FT Abs2(const Vector2d &v)
135  { return v.GetModulus2(); }
136 inline GEOM_FT Abs(const Vector2d &v)
137  { return v.GetModulus(); }
138 double signedAngle(const Vector2d &v1,const Vector2d &v2);
139 double angle(const Vector2d &v1,const Vector2d &v2);
140 
142 inline Vector2d operator*(const GEOM_FT &d,const Vector2d &v)
143  { return v*d; }
145 inline Vector2d normalize(const Vector2d &v)
146  { return v.getNormalized(); }
147 
148 //Producto tensorial.
149 FT_matrix prod_tensor(const Vector2d &u,const Vector2d &v);
150 FT_matrix operator&(const Vector2d &u,const Vector2d &v);
151 
152 bool colineales(const Vector2d &v1,const Vector2d &v2);
153 bool parallel(const Vector2d &v1,const Vector2d &v2);
154 
155 const Vector2d VectorNulo2d;
156 
157 #endif
Dirección en dos dimensiones.
Definition: Dir2d.h:36
Vector2d Normal(void) const
Return el vector normal a éste.
Definition: Vector2d.cc:153
virtual GEOM_FT GetModulus(void) const
Return el módulo del vector.
Definition: Vector2d.cc:193
Vector2d operator/(const GEOM_FT &) const
Return el producto del vector por el inverso del escalar.
Definition: Vector2d.cc:132
Vector2d operator*(const GEOM_FT &) const
Return el producto del vector por el escalar.
Definition: Vector2d.cc:128
Posición en dos dimensiones.
Definition: Pos2d.h:41
Vector2d Rotated(const double &ang_rad) const
Return the vector that results from rotating this one by the given angle.
Definition: Vector2d.cc:222
GEOM_FT getSignedAngle(const Vector2d &v) const
Return the angle with the vector argument.
Definition: Vector2d.cc:164
Vector2d getNormalized(void) const
Return el versor (vector de módulo unidad) correspondiente a éste vector.
Definition: Vector2d.h:99
void Normalize(void)
Normalize vector.
Definition: Vector2d.cc:157
Vector en dos dimensiones.
Definition: Vector2d.h:40
FT_matrix getMatrix(void) const
Return the point coordinates in a matrix.
Definition: Vector2d.cc:136
ProtoGeom(void)
False when solution is not possible: intersection of parallel planes.
Definition: ProtoGeom.cc:33
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Vector2d.cc:277
Base class for geometry objects.
Definition: ProtoGeom.h:33
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Vector2d.cc:268
GEOM_FT getAngle(const Vector2d &v) const
Return the angle with the argument vector.
Definition: Vector2d.cc:168
Vector2d operator+(const Vector2d &) const
Return la suma de los vectores.
Definition: Vector2d.cc:120
virtual bool operator==(const Vector2d &) const
Comparison operator.
Definition: Vector2d.cc:65
boost::python::list getPyList(void) const
Return the point coordinates in a Python list.
Definition: Vector2d.cc:144
Matrix which components are GEOM_FT numbers.
Definition: FT_matrix.h:40