OperationsVV.h
Go to the documentation of this file.
1 
9 #ifndef _utl_OperationsVV_h_
10 #define _utl_OperationsVV_h_
11 
12 #include <utl/Vector.h>
13 #include <cmath>
14 
15 
16 namespace utl {
17 
18  inline
19  Vector
20  operator+(const Vector& l, const Vector& r)
21  {
22  r.TransformTo(l.fCoordinateSystem);
23  return Vector(l.fVector + r.fVector, l.fCoordinateSystem);
24  }
25 
26 
27  inline
28  Vector
29  operator-(const Vector& l, const Vector& r)
30  {
31  r.TransformTo(l.fCoordinateSystem);
32  return Vector(l.fVector - r.fVector, l.fCoordinateSystem);
33  }
34 
35 
36  inline
37  Vector
38  operator*(const double d, const Vector& v)
39  {
40  return Vector(d*v.fVector, v.fCoordinateSystem);
41  }
42 
43 
44  inline
45  Vector
46  operator*(const Vector& v, const double d)
47  {
48  return Vector(d*v.fVector, v.fCoordinateSystem);
49  }
50 
51 
52  inline
53  Vector
54  operator/(const Vector& v, const double d)
55  {
56  return Vector(v.fVector/d, v.fCoordinateSystem);
57  }
58 
59 
60  inline
61  double
62  operator*(const Vector& l, const Vector& r)
63  {
64  r.TransformTo(l.fCoordinateSystem);
65  return l.fVector * r.fVector;
66  }
67 
68 
69  inline
70  double
71  CosAngle(const Vector& l, const Vector& r)
72  {
73  const double magnitudeA = l.GetMag();
74  const double magnitudeB = r.GetMag();
75  return (magnitudeA && magnitudeB) ?
76  (l * r) / (magnitudeA * magnitudeB) : 1;
77  }
78 
79 
80  inline
81  double
82  Angle(const Vector& left, const Vector& right)
83  {
84  /*const double cosAngle = CosAngle(left, right);
85  return (cosAngle >= 1) ? 0 : acos(cosAngle);*/
86  // DV: this is more accurate for small and large angles
87  const Vector a = 1/left.GetMag() * left;
88  const Vector b = 1/right.GetMag() * right;
89  const double d2 = (a - b).GetMag2();
90  if (d2 <= 2)
91  return 2 * std::asin(0.5 * std::sqrt(d2));
92  else
93  return 2 * std::acos(0.5 * (a + b).GetMag());
94  }
95 
96 }
97 
98 
99 #endif
Point operator-(const Point &l, const Vector &r)
Definition: OperationsPV.h:37
fs::path operator+(const fs::path &thePath, const string &extra)
Definition: FileName.cc:73
Vector operator/(const Vector &v, const double d)
Definition: OperationsVV.h:54
double GetMag() const
Definition: Vector.h:58
DataType fVector
Definition: BasicVector.h:360
Vector operator*(const double d, const Vector &v)
Definition: OperationsVV.h:38
CoordinateSystemPtr fCoordinateSystem
Definition: BasicVector.h:359
double Angle(const Vector &left, const Vector &right)
Definition: OperationsVV.h:82
Vector object.
Definition: Vector.h:30
double CosAngle(const Vector &l, const Vector &r)
Definition: OperationsVV.h:71

, generated on Tue Sep 26 2023.