OpenLexocad  27.1
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/XYZ.h>
28 #include <QString>
29 
30 namespace Geom
31 {
32 class Ax1;
33 class Ax2;
34 class Trsf;
35 class Dir;
36 class Pnt;
37 class Vec;
38 
39 } // namespace Geom
40 
41 namespace Geom
42 {
44 class LX_GEOM_EXPORT Vec
45 {
46 public:
48  // //
49  // --------------------- BEGIN API --------------------- //
50  // //
51  // ATTENTION: DO NOT CHANGE ANY SIGNATURES IN THE API ! //
52  // //
54 
55  // Methods PUBLIC
56  //
58  Vec();
60  Vec(const Geom::Dir& V);
62  Vec(const Geom::XYZ& Coord);
64  Vec(const double Xv, const double Yv, const double Zv);
65 
68  Vec(const Geom::Pnt& P1, const Geom::Pnt& P2);
69 
71  Vec(const Vec& rhs);
72 
77  void setCoord(const int Index, const double Xi);
80  void setCoord(const double Xv, const double Yv, const double Zv);
82  void setX(const double X);
84  void setY(const double Y);
86  void setZ(const double Z);
88  void setXYZ(const Geom::XYZ& Coord);
89 
94  double coord(const int Index) const;
96  void coord(double& Xv, double& Yv, double& Zv) const;
98  double x() const;
100  double y() const;
102  double z() const;
105  const Geom::XYZ& xyz() const;
106 
107  float fx() const;
108  float fy() const;
109  float fz() const;
110 
111 
115  bool isEqual(const Vec& Other, const double LinearTolerance, const double AngularTolerance) const;
116 
120  bool isNormal(const Vec& Other, const double AngularTolerance) const;
121 
125  bool isOpposite(const Vec& Other, const double AngularTolerance) const;
126 
133  bool isParallel(const Vec& Other, const double AngularTolerance) const;
134 
140  double angle(const Vec& Other) const;
155  double angleWithRef(const Vec& Other, const Vec& VRef) const;
157  double magnitude() const;
159  double squareMagnitude() const;
160 
161  void add(const Vec& Other);
162  void operator+=(const Vec& Other) { add(Other); }
163 
165  Vec added(const Vec& Other) const;
166  Vec operator+(const Vec& Other) const { return added(Other); }
167 
168 
169  void subtract(const Vec& Right);
170  void operator-=(const Vec& Right) { subtract(Right); }
171 
173  Vec subtracted(const Vec& Right) const;
174  Vec operator-(const Vec& Right) const { return subtracted(Right); }
175 
176 
177  void multiply(const double Scalar);
178  void operator*=(const double Scalar) { multiply(Scalar); }
179 
181  Vec multiplied(const double Scalar) const;
182  Vec operator*(const double Scalar) const { return multiplied(Scalar); }
183 
184 
185  void divide(const double Scalar);
186  void operator/=(const double Scalar) { divide(Scalar); }
187 
189  Vec divided(const double Scalar) const;
190  Vec operator/(const double Scalar) const { return divided(Scalar); }
191 
192 
193  void cross(const Vec& Right);
194  void operator^=(const Vec& Right) { cross(Right); }
195 
197  Vec crossed(const Vec& Right) const;
198  Vec operator^(const Vec& Right) const { return crossed(Right); }
199 
200 
204  double crossMagnitude(const Vec& Right) const;
205 
210  double crossSquareMagnitude(const Vec& Right) const;
211 
212  void crossCross(const Vec& V1, const Vec& V2);
215  Vec crossCrossed(const Vec& V1, const Vec& V2) const;
217  double dot(const Vec& Other) const;
218  double operator*(const Vec& Other) const { return dot(Other); }
219 
223  double dotCross(const Vec& V1, const Vec& V2) const;
224 
225  void normalize();
229  Vec normalized() const;
230 
231  void reverse();
233  Vec reversed() const;
234  Vec operator-() const { return reversed(); }
235  Vec operator & (const Vec& rcVct) const;
236 
237 
240  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const double A3, const Vec& V3, const Vec& V4);
241 
244  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const double A3, const Vec& V3);
245 
248  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2, const Vec& V3);
249 
252  void setLinearForm(const double A1, const Vec& V1, const double A2, const Vec& V2);
253 
255  void setLinearForm(const double A1, const Vec& V1, const Vec& V2);
256 
258  void setLinearForm(const Vec& V1, const Vec& V2);
259 
260 
261  void mirror(const Vec& V);
262 
263 
267  Vec mirrored(const Vec& V) const;
268 
269 
270  void mirror(const Geom::Ax1& A1);
271 
272 
276  Vec mirrored(const Geom::Ax1& A1) const;
277 
278 
279  void mirror(const Geom::Ax2& A2);
280 
281 
285  Vec mirrored(const Geom::Ax2& A2) const;
286 
287  void rotate(const Geom::Ax1& A1, const double Ang);
288 
291  Vec rotated(const Geom::Ax1& A1, const double Ang) const;
292 
293  void scale(const double S);
295  Vec scaled(const double S) const;
296 
297 
298  void transform(const Geom::Trsf& T);
300  Vec transformed(const Geom::Trsf& T) const;
302 
308  Geom::Vec& projectToLine(const Geom::Vec& rclPoint, const Geom::Vec& rclLine);
309 
314  Geom::Vec perpendicular(const Geom::Vec& rclBase, const Geom::Vec& rclDir) const;
315 
320  double distanceToPlane(const Geom::Vec& rclBase, const Geom::Vec& rclNorm) const;
322  double distanceToLine(const Geom::Vec& rclBase, const Geom::Vec& rclDirect) const;
328  Geom::Vec distanceToLineSegment(const Geom::Vec& rclP1, const Geom::Vec& rclP2) const;
329 
331  // //
332  // ---------------------- END API ---------------------- //
333  // //
335 
336  double& operator[](int i);
337 
338 private:
339  Geom::XYZ _coord;
340 };
341 
342 // global functions
343 
345 inline double distance(const Geom::Vec& v1, const Geom::Vec& v2)
346 {
347  double x = v1.x() - v2.x(), y = v1.y() - v2.y(), z = v1.z() - v2.z();
348  return static_cast<double>(sqrt((x * x) + (y * y) + (z * z)));
349 }
350 
352 inline double distanceP2(const Geom::Vec& v1, const Geom::Vec& v2)
353 {
354  double x = v1.x() - v2.x(), y = v1.y() - v2.y(), z = v1.z() - v2.z();
355  return x * x + y * y + z * z;
356 }
357 
358 LX_GEOM_EXPORT QString to_string(const Vec& vec);
359 } // namespace Geom
360 
361 inline Geom::Vec operator*(const double Scalar, const Geom::Vec& V)
362 {
363  return V.multiplied(Scalar);
364 }
365 
366 
367 
368 #pragma warning(pop)
Definition: Variant.h:60
Vec operator-() const
Definition: Vec.h:234
X
Definition: Globals.h:29
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:43
Vector3f & operator *=(Vector3f &rclVect, const Matrix4D &rclMtrx)
Definition: Matrix.h:351
void operator/=(const double Scalar)
Definition: Vec.h:186
double x() const
For this vector, returns its X coordinate.
Vec operator-(const Vec &Right) const
Definition: Vec.h:174
Vec operator^(const Vec &Right) const
Definition: Vec.h:198
Vec operator/(const double Scalar) const
Definition: Vec.h:190
void transform(Container container, OutputIt out, BinaryFunction function)
Definition: Algorithms.h:29
void operator-=(const Vec &Right)
Definition: Vec.h:170
Definition: Ax2.h:67
Definition: XYZ.h:43
double z() const
For this vector, returns its Z coordinate.
Definition: Trsf.h:57
Definition: Dir.h:45
void operator^=(const Vec &Right)
Definition: Vec.h:194
Y
Definition: Globals.h:29
LX_GEOM_EXPORT QString to_string(const Dir &dir)
Definition: Ax1.h:50
Z
Definition: Globals.h:29
Defines a non-persistent vector in 3D space.
Definition: Vec.h:44
double distance(const Geom::Vec &v1, const Geom::Vec &v2)
Returns the distance between two points.
Definition: Vec.h:345
double distanceP2(const Geom::Vec &v1, const Geom::Vec &v2)
Returns the squared distance between two points.
Definition: Vec.h:352
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:361
double y() const
For this vector, returns its Y coordinate.
Vec operator+(const Vec &Other) const
Definition: Vec.h:166
void operator+=(const Vec &Other)
Definition: Vec.h:162