OpenLexocad  28.0
Vec2d.h
Go to the documentation of this file.
1 //
3 // Copyright(C) 2013-2016 OpenCascade [www.opencascade.org]
4 //
5 // This library is free software; you can redistribute it and / or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street,
18 // Fifth Floor, Boston, MA 02110 - 1301 USA
19 //
21 
22 #pragma once
23 #include <Geom/Pnt2d.h>
24 
25 namespace Geom
26 {
27 class Ax2d;
28 class Dir2d;
29 class Trsf2d;
30 
32 class LX_GEOM_EXPORT Vec2d
33 {
34 public:
36  Vec2d();
38  Vec2d(const Dir2d& V);
40  Vec2d(const XY& Coord);
42  Vec2d(const double Xv, const double Yv);
43 
46  Vec2d(const Pnt2d& P1, const Pnt2d& P2);
47  void add(const Vec2d& Other);
49  Vec2d added(const Vec2d& Other) const;
54  double angle(const Vec2d& Other) const;
58  double coord(const int Index) const;
60  void coord(double& Xv, double& Yv) const;
62  double crossed(const Vec2d& Right) const;
65  double crossMagnitude(const Vec2d& Right) const;
66 
69  double crossSquareMagnitude(const Vec2d& Right) const;
70 
71  void divide(const double Scalar);
73  Vec2d divided(const double Scalar) const;
75  double dot(const Vec2d& Other) const;
79  bool isEqual(const Vec2d& Other, const double LinearTolerance, const double AngularTolerance) const;
80 
82  bool isNormal(const Vec2d& Other, const double AngularTolerance) const;
83 
85  bool isOpposite(const Vec2d& Other, const double AngularTolerance) const;
86 
90  bool isParallel(const Vec2d& Other, const double AngularTolerance) const;
91 
93  double magnitude() const;
95  double squareMagnitude() const;
96 
97  void operator+=(const Vec2d& Other) { add(Other); }
98  Vec2d operator+(const Vec2d& Other) const { return added(Other); }
99  void operator-=(const Vec2d& Right) { subtract(Right); }
100  Vec2d operator-() const { return reversed(); }
101 
102  Vec2d operator-(const Vec2d& Right) const { return subtracted(Right); }
103 
104  void operator*=(const double Scalar) { multiply(Scalar); }
105  double operator*(const Vec2d& Other) const { return dot(Other); }
106 
107  Vec2d operator*(const double Scalar) const { return multiplied(Scalar); }
108 
109  void operator/=(const double Scalar) { divide(Scalar); }
110  Vec2d operator/(const double Scalar) const { return divided(Scalar); }
111  double operator^(const Vec2d& Right) const { return crossed(Right); }
112 
113  void multiply(const double Scalar);
117  Vec2d multiplied(const double Scalar) const;
118  void mirror(const Vec2d& V);
119 
120  void mirror(const Ax2d& A1);
121 
125  Vec2d mirrored(const Ax2d& A1) const;
126 
133  Vec2d mirrored(const Vec2d& V) const;
134 
135  void normalize();
139  Vec2d normalized() const;
140 
141  void reverse();
143  Vec2d reversed() const;
144  void rotate(const double Ang);
145 
148  Vec2d rotated(const double Ang) const;
149 
150  void scale(const double S);
152  Vec2d scaled(const double S) const;
153 
158  void setCoord(const int Index, const double Xi);
161  void setCoord(const double Xv, const double Yv);
164  void setLinearForm(const double A1, const Vec2d& V1, const double A2, const Vec2d& V2, const Vec2d& V3);
165 
167  void setLinearForm(const double A1, const Vec2d& V1, const double A2, const Vec2d& V2);
168 
170  void setLinearForm(const double A1, const Vec2d& V1, const Vec2d& V2);
171 
176  void setLinearForm(const Vec2d& Left, const Vec2d& Right);
177 
179  void setX(const double X);
181  void setXY(const XY& Coord);
182 
184  void setY(const double Y);
185  void subtract(const Vec2d& Right);
187  Vec2d subtracted(const Vec2d& Right) const;
188  void transform(const Trsf2d& T);
190  Vec2d transformed(const Trsf2d& T) const;
191 
193  double x() const;
195  const XY& xy() const;
196 
198  double y() const;
199 
200 protected:
201 private:
202  XY _coord;
203 };
204 } // namespace Geom
Geom::Vec2d::divided
Vec2d divided(const double Scalar) const
divides a vector by a scalar
Geom::Vec2d::dot
double dot(const Vec2d &Other) const
Computes the scalar product
Geom::Vec2d::rotated
Vec2d rotated(const double Ang) const
Geom::Vec2d::added
Vec2d added(const Vec2d &Other) const
Adds two vectors
Geom::Vec2d::y
double y() const
For this vector, returns its Y coordinate.
Geom::Vec2d::Vec2d
Vec2d(const double Xv, const double Yv)
Creates a point with its two cartesian coordinates.
Geom::Vec2d::isNormal
bool isNormal(const Vec2d &Other, const double AngularTolerance) const
Returns True if abs(abs(<me>.angle(Other)) - PI/2.) <= AngularTolerance
Geom::Vec2d::setXY
void setXY(const XY &Coord)
Assigns the two coordinates of Coord to this vector.
Geom::Vec2d::setX
void setX(const double X)
Assigns the given value to the X coordinate of this vector.
Geom::Vec2d::transformed
Vec2d transformed(const Trsf2d &T) const
Geom::Vec2d::angle
double angle(const Vec2d &Other) const
Geom::Vec2d::coord
void coord(double &Xv, double &Yv) const
For this vector, returns its two coordinates Xv and Yv
Geom::Vec2d::isEqual
bool isEqual(const Vec2d &Other, const double LinearTolerance, const double AngularTolerance) const
Geom::Vec2d::setLinearForm
void setLinearForm(const double A1, const Vec2d &V1, const double A2, const Vec2d &V2, const Vec2d &V3)
Geom::Vec2d::scaled
Vec2d scaled(const double S) const
Scales a vector. S is the scaling value.
Geom::Vec2d::divide
void divide(const double Scalar)
Geom::Vec2d::isOpposite
bool isOpposite(const Vec2d &Other, const double AngularTolerance) const
Returns True if PI - abs(<me>.angle(Other)) <= AngularTolerance
Geom::Vec2d::multiply
void multiply(const double Scalar)
Geom::Vec2d::transform
void transform(const Trsf2d &T)
Geom::Vec2d::setLinearForm
void setLinearForm(const Vec2d &Left, const Vec2d &Right)
Geom::Vec2d::operator+=
void operator+=(const Vec2d &Other)
Definition: Vec2d.h:97
Geom::Vec2d::rotate
void rotate(const double Ang)
Geom::Vec2d::crossSquareMagnitude
double crossSquareMagnitude(const Vec2d &Right) const
Geom::Vec2d::Vec2d
Vec2d()
Creates an indefinite vector.
X
X
Definition: Globals.h:29
Geom::Vec2d::isParallel
bool isParallel(const Vec2d &Other, const double AngularTolerance) const
Geom::Vec2d::setLinearForm
void setLinearForm(const double A1, const Vec2d &V1, const double A2, const Vec2d &V2)
<me> is setted to the following linear form : A1 * V1 + A2 * V2
Geom::Vec2d::x
double x() const
For this vector, returns its X coordinate.
Geom::Vec2d::crossed
double crossed(const Vec2d &Right) const
Computes the crossing product between two vectors
Geom::Vec2d::xy
const XY & xy() const
For this vector, returns its two coordinates as a number pair
Geom::Vec2d::normalized
Vec2d normalized() const
Geom::XY
Definition: XY.h:34
Geom::Vec2d::mirrored
Vec2d mirrored(const Vec2d &V) const
Geom::Vec2d::coord
double coord(const int Index) const
Geom::Vec2d::operator+
Vec2d operator+(const Vec2d &Other) const
Definition: Vec2d.h:98
Geom::Vec2d::reverse
void reverse()
Geom::Vec2d::multiplied
Vec2d multiplied(const double Scalar) const
Geom::Dir2d
Definition: Dir2d.h:42
Geom::Vec2d::add
void add(const Vec2d &Other)
Geom::Vec2d::mirror
void mirror(const Vec2d &V)
Geom::Vec2d::reversed
Vec2d reversed() const
Reverses the direction of a vector //! Subtracts two vectors
Geom::Vec2d::setY
void setY(const double Y)
Assigns the given value to the Y coordinate of this vector.
Geom::Vec2d::Vec2d
Vec2d(const Dir2d &V)
Creates a unitary vector from a direction V.
Geom::Vec2d::subtracted
Vec2d subtracted(const Vec2d &Right) const
Subtracts two vectors
Geom::Vec2d::setCoord
void setCoord(const int Index, const double Xi)
Geom::Vec2d::operator*
Vec2d operator*(const double Scalar) const
Definition: Vec2d.h:107
Geom::Vec2d
Defines a non-persistent vector in 2D space.
Definition: Vec2d.h:33
Geom::Vec2d::operator-
Vec2d operator-() const
Definition: Vec2d.h:100
Pnt2d.h
Geom::Ax2d
Definition: Ax2d.h:51
Geom::Vec2d::operator-=
void operator-=(const Vec2d &Right)
Definition: Vec2d.h:99
Geom::Vec2d::operator-
Vec2d operator-(const Vec2d &Right) const
Definition: Vec2d.h:102
Y
Y
Definition: Globals.h:30
Geom::Vec2d::crossMagnitude
double crossMagnitude(const Vec2d &Right) const
Geom::Vec2d::Vec2d
Vec2d(const XY &Coord)
Creates a vector with a doublet of coordinates.
Geom::Vec2d::setCoord
void setCoord(const double Xv, const double Yv)
Geom::Vec2d::operator/=
void operator/=(const double Scalar)
Definition: Vec2d.h:109
Geom::Vec2d::magnitude
double magnitude() const
Computes the magnitude of this vector.
Geom::Vec2d::operator*=
void operator*=(const double Scalar)
Definition: Vec2d.h:104
Geom::Vec2d::operator/
Vec2d operator/(const double Scalar) const
Definition: Vec2d.h:110
Geom::Vec2d::mirror
void mirror(const Ax2d &A1)
Geom::Vec2d::squareMagnitude
double squareMagnitude() const
Computes the square magnitude of this vector.
Geom::Pnt2d
Defines a non-persistent 2D cartesian point.
Definition: Pnt2d.h:34
Geom::Trsf2d
Definition: Trsf2d.h:47
Geom::Vec2d::mirrored
Vec2d mirrored(const Ax2d &A1) const
Geom::Vec2d::subtract
void subtract(const Vec2d &Right)
Geom::Vec2d::setLinearForm
void setLinearForm(const double A1, const Vec2d &V1, const Vec2d &V2)
<me> is setted to the following linear form : A1 * V1 + V2
Geom::Vec2d::normalize
void normalize()
Geom::Vec2d::scale
void scale(const double S)
Geom::Vec2d::operator*
double operator*(const Vec2d &Other) const
Definition: Vec2d.h:105
Geom::Vec2d::operator^
double operator^(const Vec2d &Right) const
Definition: Vec2d.h:111
Geom
Definition: PropertyContainer.h:33
Geom::Vec2d::Vec2d
Vec2d(const Pnt2d &P1, const Pnt2d &P2)