123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using UnityEngine;
- using M = System.Math;
- namespace ARLocation
- {
- [System.Serializable]
- public struct DVector3
- {
- public double x;
- public double y;
- public double z;
- public DVector3(Vector3 v)
- {
- x = v.x;
- y = v.y;
- z = v.z;
- }
-
-
-
-
- public double magnitude
- {
- get
- {
- return M.Sqrt(x * x + y * y + z * z);
- }
- }
-
-
-
-
- public DVector3 normalized
- {
- get
- {
- var m = magnitude;
- if (m < 0.00000001)
- {
- return new DVector3();
- }
- return new DVector3(x, y, z) / magnitude;
- }
- }
-
-
-
- public DVector3(double newX = 0.0, double newY = 0.0, double newZ = 0.0)
- {
- x = newX;
- y = newY;
- z = newZ;
- }
-
-
-
-
- public Vector3 toVector3()
- {
- return new Vector3((float)x, (float)y, (float)z);
- }
-
-
-
-
-
-
- public bool Equals(DVector3 v, double e = 0.00005)
- {
- return (M.Abs(x - v.x) <= e) && (M.Abs(y - v.y) <= e) && (M.Abs(z - v.z) <= e);
- }
-
-
-
- public void Normalize()
- {
- double m = magnitude;
- x /= m;
- y /= m;
- z /= m;
- }
-
-
-
-
-
-
- public void Set(double xx = 0.0, double yy = 0.0, double zz = 0.0)
- {
- x = xx;
- y = yy;
- z = zz;
- }
-
-
-
-
- override public string ToString()
- {
- return "(" + x + ", " + y + ", " + z + ")";
- }
-
-
-
-
-
-
- public static double Dot(DVector3 a, DVector3 b)
- {
- return a.x * b.x + a.y * b.y + a.z * b.z;
- }
-
-
-
-
-
-
- public static double Distance(DVector3 a, DVector3 b)
- {
- return M.Sqrt(a.x * b.x + a.y * b.y + a.z * b.z);
- }
-
-
-
-
-
-
-
- public static DVector3 Lerp(DVector3 a, DVector3 b, double t)
- {
- double s = M.Max(0, M.Min(t, 1));
- return a * (1 - s) + b * s;
- }
-
-
-
-
-
-
- public static DVector3 operator *(DVector3 a, double b)
- {
- return new DVector3(
- b * a.x,
- b * a.y,
- b * a.z
- );
- }
-
-
-
-
-
-
- public static DVector3 operator *(double b, DVector3 a)
- {
- return new DVector3(
- b * a.x,
- b * a.y,
- b * a.z
- );
- }
-
-
-
-
-
-
- public static DVector3 operator /(DVector3 a, double b)
- {
- return new DVector3(
- a.x / b,
- a.y / b,
- a.z / b
- );
- }
-
-
-
-
-
-
- public static DVector3 operator +(DVector3 a, DVector3 b)
- {
- return new DVector3(
- a.x + b.x,
- a.y + b.y,
- a.z + b.z
- );
- }
-
-
-
-
-
-
- public static DVector3 operator -(DVector3 a, DVector3 b)
- {
- return new DVector3(
- a.x - b.x,
- a.y - b.y,
- a.z - b.z
- );
- }
- }
- }
|