AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
DVector3.cs
1 using UnityEngine;
2 using M = System.Math;
3 // ReSharper disable InconsistentNaming
4 
5 namespace ARLocation
6 {
7  [System.Serializable]
8  public struct DVector3
9  {
10  public double x;
11  public double y;
12  public double z;
13 
14  public DVector3(Vector3 v)
15  {
16  x = v.x;
17  y = v.y;
18  z = v.z;
19  }
20 
25  public double magnitude
26  {
27  get
28  {
29  return M.Sqrt(x * x + y * y + z * z);
30  }
31  }
32 
38  {
39  get
40  {
41  var m = magnitude;
42 
43  if (m < 0.00000001)
44  {
45  return new DVector3();
46  }
47 
48  return new DVector3(x, y, z) / magnitude;
49  }
50  }
51 
55  public DVector3(double newX = 0.0, double newY = 0.0, double newZ = 0.0)
56  {
57  x = newX;
58  y = newY;
59  z = newZ;
60  }
61 
66  public Vector3 toVector3()
67  {
68  return new Vector3((float)x, (float)y, (float)z);
69  }
70 
77  public bool Equals(DVector3 v, double e = 0.00005)
78  {
79  return (M.Abs(x - v.x) <= e) && (M.Abs(y - v.y) <= e) && (M.Abs(z - v.z) <= e);
80  }
81 
85  public void Normalize()
86  {
87  double m = magnitude;
88  x /= m;
89  y /= m;
90  z /= m;
91  }
92 
99  public void Set(double xx = 0.0, double yy = 0.0, double zz = 0.0)
100  {
101  x = xx;
102  y = yy;
103  z = zz;
104  }
105 
110  override public string ToString()
111  {
112  return "(" + x + ", " + y + ", " + z + ")";
113  }
114 
121  public static double Dot(DVector3 a, DVector3 b)
122  {
123  return a.x * b.x + a.y * b.y + a.z * b.z;
124  }
125 
132  public static double Distance(DVector3 a, DVector3 b)
133  {
134  return M.Sqrt(a.x * b.x + a.y * b.y + a.z * b.z);
135  }
136 
144  public static DVector3 Lerp(DVector3 a, DVector3 b, double t)
145  {
146  double s = M.Max(0, M.Min(t, 1));
147  return a * (1 - s) + b * s;
148  }
149 
156  public static DVector3 operator *(DVector3 a, double b)
157  {
158  return new DVector3(
159  b * a.x,
160  b * a.y,
161  b * a.z
162  );
163  }
164 
171  public static DVector3 operator *(double b, DVector3 a)
172  {
173  return new DVector3(
174  b * a.x,
175  b * a.y,
176  b * a.z
177  );
178  }
179 
186  public static DVector3 operator /(DVector3 a, double b)
187  {
188  return new DVector3(
189  a.x / b,
190  a.y / b,
191  a.z / b
192  );
193  }
194 
201  public static DVector3 operator +(DVector3 a, DVector3 b)
202  {
203  return new DVector3(
204  a.x + b.x,
205  a.y + b.y,
206  a.z + b.z
207  );
208  }
209 
216  public static DVector3 operator -(DVector3 a, DVector3 b)
217  {
218  return new DVector3(
219  a.x - b.x,
220  a.y - b.y,
221  a.z - b.z
222  );
223  }
224  }
225 }
ARLocation.DVector3.Set
void Set(double xx=0.0, double yy=0.0, double zz=0.0)
Set the specified x and y.
Definition: DVector3.cs:99
ARLocation.DVector3.Equals
bool Equals(DVector3 v, double e=0.00005)
Equals the specified v and e.
Definition: DVector3.cs:77
ARLocation.DVector3.Dot
static double Dot(DVector3 a, DVector3 b)
Dot the specified a and b.
Definition: DVector3.cs:121
ARLocation.DVector3
Definition: DVector3.cs:9
ARLocation.DVector3.normalized
DVector3 normalized
Gets the normalized version of this vector.
Definition: DVector3.cs:38
ARLocation.DVector3.Lerp
static DVector3 Lerp(DVector3 a, DVector3 b, double t)
Lerp the specified a, b and t.
Definition: DVector3.cs:144
ARLocation.DVector3.Normalize
void Normalize()
Normalize this instance.
Definition: DVector3.cs:85
ARLocation.DVector3.toVector3
Vector3 toVector3()
Converts to a Vector3.
Definition: DVector3.cs:66
ARLocation.DVector3.magnitude
double magnitude
Gets the magnitude of the vector.
Definition: DVector3.cs:26
ARLocation.DVector3.DVector3
DVector3(double newX=0.0, double newY=0.0, double newZ=0.0)
Initializes a new instance of the T:DVector3 struct.
Definition: DVector3.cs:55
ARLocation.DVector3.operator+
static DVector3 operator+(DVector3 a, DVector3 b)
Adds a DVector3 to a DVector3, yielding a new T:DVector3.
Definition: DVector3.cs:201
ARLocation.DVector3.ToString
override string ToString()
Returns a T:System.String that represents the current T:DVector3.
Definition: DVector3.cs:110
ARLocation.DVector3.operator/
static DVector3 operator/(DVector3 a, double b)
Computes the division of a and b, yielding a new T:DVector3.
Definition: DVector3.cs:186
ARLocation
Definition: ARLocationConfigInspector.cs:7
ARLocation.DVector3.operator*
static DVector3 operator*(DVector3 a, double b)
Computes the product of a and b, yielding a new T:DVector3.
Definition: DVector3.cs:156
ARLocation.DVector3.operator-
static DVector3 operator-(DVector3 a, DVector3 b)
Subtracts a DVector3 from a DVector3, yielding a new T:DVector3.
Definition: DVector3.cs:216
ARLocation.DVector3.Distance
static double Distance(DVector3 a, DVector3 b)
Distance the specified a and b.
Definition: DVector3.cs:132