OpenLexocad  27.0
Vec.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 
24 #pragma warning(push)
25 #pragma warning(disable : 4251)
26 
27 #include <Geom/GeomEnums.h>
28 #include <Geom/XYZ.h>
29 #include <Geom/geom_defines.h>
30 
31 namespace Geom
32 {
33 class Ax1;
34 class Ax2;
35 class Trsf;
36 class Dir;
37 class Pnt;
38 class Vec;
39 
40 } // namespace Geom
41 
42 namespace Geom
43 {
46 {
47 public:
49  // //
50  // --------------------- BEGIN API --------------------- //
51  // //
52  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
53  // //
55 
56  // Methods PUBLIC
57  //
59  Vec();
61  Vec(const Geom::Dir& V);
63  Vec(const Geom::XYZ& Coord);
65  Vec(const double Xv, const double Yv, const double Zv);
66 
69  Vec(const Geom::Pnt& P1, const Geom::Pnt& P2);
70 
72  Vec(const Vec& rhs);
73 
78  void setCoord(const int Index, const double Xi);
81  void setCoord(const double Xv, const double Yv, const double Zv);
83  void setX(const double X);
85  void setY(const double Y);
87  void setZ(const double Z);
89  void setXYZ(const Geom::XYZ& Coord);
90 
95  double coord(const int Index) const;
97  void coord(double& Xv, double& Yv, double& Zv) const;
99  double x() const;
101  double y() const;
103  double z() const;
106  const Geom::XYZ& xyz() const;
107 
108 
112  bool isEqual(const Vec& Other, const double LinearTolerance, const double AngularTolerance) const;
113 
117  bool isNormal(const Vec& Other, const double AngularTolerance) const;
118 
122  bool isOpposite(const Vec& Other, const double AngularTolerance) const;
123 
130  bool isParallel(const Vec& Other, const double AngularTolerance) const;
131 
137  double angle(const Vec& Other) const;
152  double angleWithRef(const Vec& Other, const Vec& VRef) const;
154  double magnitude() const;
156  double squareMagnitude() const;
157 
158  void add(const Vec& Other);
159  void operator+=(const Vec& Other) { add(Other); }
160 
162  Vec added(const Vec& Other) const;
163  Vec operator+(const Vec& Other) const { return added(Other); }
164 
165 
166  void subtract(const Vec& Right);
167  void operator-=(const Vec& Right) { subtract(Right); }
168 
170  Vec subtracted(const Vec& Right) const;
171  Vec operator-(const Vec& Right) const { return subtracted(Right); }
172 
173 
174  void multiply(const double Scalar);
175  void operator*=(const double Scalar) { multiply(Scalar); }
176 
178  Vec multiplied(const double Scalar) const;
179  Vec operator*(const double Scalar) const { return multiplied(Scalar); }
180 
181 
182  void divide(const double Scalar);
183  void operator/=(const double Scalar) { divide(Scalar); }
184 
186  Vec divided(const double Scalar) const;
187  Vec operator/(const double Scalar) const { return divided(Scalar); }
188 
189 
190  void cross(const Vec& Right);
191  void operator^=(const Vec& Right) { cross(Right); }
192 
194  Vec crossed(const Vec& Right) const;
195  Vec operator^(const Vec& Right) const { return crossed(Right); }
196 
197 
201  double crossMagnitude(const Vec& Right) const;
202 
207  double crossSquareMagnitude(const Vec& Right) const;
208 
209  void crossCross(const Vec& V1, const Vec& V2);
212  Vec crossCrossed(const Vec& V1, const Vec& V2) const;
214  double dot(const Vec& Other) const;
215  double operator*(const Vec& Other) const { return dot(Other); }
216 
220  double dotCross(const Vec& V1, const Vec& V2) const;
221 
222  void normalize();
226  Vec normalized() const;
227 
228  void reverse();
230  Vec reversed() const;
231  Vec operator-() const { return reversed(); }
232 
233 
236  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const double A3, const Vec& V3, const Vec& V4);
237 
240  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const double A3, const Vec& V3);
241 
244  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const Vec& V3);
245 
248  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2);
249 
251  void setLinearForm(const double A1, const Vec& V1, const Vec& V2);
252 
254  void setLinearForm(const Vec& V1, const Vec& V2);
255 
256 
257  void mirror(const Vec& V);
258 
259 
263  Vec mirrored(const Vec& V) const;
264 
265 
266  void mirror(const Geom::Ax1& A1);
267 
268 
272  Vec mirrored(const Geom::Ax1& A1) const;
273 
274 
275  void mirror(const Geom::Ax2& A2);
276 
277 
281  Vec mirrored(const Geom::Ax2& A2) const;
282 
283  void rotate(const Geom::Ax1& A1, const double Ang);
284 
287  Vec rotated(const Geom::Ax1& A1, const double Ang) const;
288 
289  void scale(const double S);
291  Vec scaled(const double S) const;
292 
293 
294  void transform(const Geom::Trsf& T);
296  Vec transformed(const Geom::Trsf& T) const;
297 
299  // //
300  // ---------------------- END API ---------------------- //
301  // //
303 
304  double& operator[](int i);
305 
306 private:
307  Geom::XYZ _coord;
308 };
309 
310 } // namespace Geom
311 
312 inline Geom::Vec operator*(const double Scalar, const Geom::Vec& V)
313 {
314  return V.multiplied(Scalar);
315 }
316 
317 #pragma warning(pop)
Definition: Rotation.h:5
Vec operator-() const
Definition: Vec.h:231
X
Definition: Globals.h:32
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:42
void operator/=(const double Scalar)
Definition: Vec.h:183
Vec operator-(const Vec &Right) const
Definition: Vec.h:171
#define GEOM_EXPORT
Definition: geom_defines.h:8
Vec operator^(const Vec &Right) const
Definition: Vec.h:195
Vec operator/(const double Scalar) const
Definition: Vec.h:187
void operator-=(const Vec &Right)
Definition: Vec.h:167
Definition: Ax2.h:69
Definition: XYZ.h:46
Definition: Trsf.h:58
Definition: Dir.h:46
void operator^=(const Vec &Right)
Definition: Vec.h:191
Y
Definition: Globals.h:32
Definition: Ax1.h:52
Z
Definition: Globals.h:32
Defines a non-persistent vector in 3D space.
Definition: Vec.h:45
Vec multiplied(const double Scalar) const
Multiplies a vector by a scalar //! Divides a vector by a scalar
Geom::Vec operator *(const double Scalar, const Geom::Vec &V)
Definition: Vec.h:312
Vec operator+(const Vec &Other) const
Definition: Vec.h:163
void operator+=(const Vec &Other)
Definition: Vec.h:159