AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
Line.cs
1 using UnityEngine;
2 
3 namespace ARLocation
4 {
5  public class Line : Curve
6  {
7  private Vector3 p0;
8  private Vector3 p1;
9 
10  private float distance;
11 
12  public Vector3 P0
13  {
14  get
15  {
16  return p0;
17  }
18  set
19  {
20  p0 = value;
21  Calculate();
22  }
23  }
24 
25  public Vector3 P1
26  {
27  get
28  {
29  return p1;
30  }
31  set
32  {
33  p1 = value;
34  Calculate();
35  }
36  }
37 
38  public Line(Vector3 p0, Vector3 p1)
39  {
40  this.p0 = p0;
41  this.p1 = p1;
42 
43  Calculate();
44  }
45 
46  public void Calculate()
47  {
48  distance = Vector3.Distance(p1, p0);
49  }
50 
51  public override float EstimateLength(int n = 100)
52  {
53  return distance;
54  }
55 
56  public override float GetParameterForLength(float s)
57  {
58  return s / distance;
59  }
60 
61  public override Vector3 GetPoint(float u)
62  {
63  return p0 * (1 - u) + p1 * u;
64  }
65 
66  public Vector3 GetTangent(float u)
67  {
68  return (p1 - p0) / distance;
69  }
70 
71  public override CurvePointData GetPointAndTangent(float u)
72  {
73  return new CurvePointData
74  {
75  point = GetPoint(u),
76  tangent = GetTangent(u)
77  };
78  }
79 
80  public override CurvePointData GetPointAndTangentAtLength(float s)
81  {
82  var u = GetParameterForLength(s);
83 
84  return GetPointAndTangent(u);
85  }
86 
87  public override Vector3 GetPointAtLength(float s)
88  {
89  var u = GetParameterForLength(s);
90 
91  return GetPoint(u);
92  }
93 
94  public override Vector3[] Sample(int n)
95  {
96  if (n == 0)
97  {
98  return new[] { GetPoint(0), GetPoint(1) };
99  }
100 
101  var sample = new Vector3[n + 2];
102  var delta = 1.0f / (n + 1.0f);
103 
104  for (var i = 0; i < (n + 2); i++)
105  {
106  sample[i] = GetPoint(i * delta);
107  }
108 
109  return sample;
110  }
111  }
112 }
ARLocation.CurvePointData
A struct holding a pair of point/tangent values.
Definition: Curve.cs:10
ARLocation.Curve
Definition: Curve.cs:17
ARLocation
Definition: ARLocationConfigInspector.cs:7
ARLocation.Line
Definition: Line.cs:6