AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
CatmullRomSpline.cs
1 using UnityEngine;
2 
3 namespace ARLocation
4 {
5 
10  public class CatmullRomSpline : Spline
11  {
12 
16  private Vector3 startHandle;
17 
21  private Vector3 endHandle;
22 
26  public float Alpha
27  {
28  get
29  {
30  return alpha;
31  }
32  set
33  {
34  alpha = value;
35  CalculateSegments(lastSampleSize);
36  }
37  }
38 
39  float alpha;
40  int lastSampleSize;
41 
48  public CatmullRomSpline(Vector3[] points, int n, float alpha)
49  {
50  Points = (Vector3[])points.Clone();
51  this.alpha = alpha;
52 
54  }
55 
60  public sealed override void CalculateSegments(int n)
61  {
62  lastSampleSize = n;
63 
64  segmentCount = (Points.Length - 1);
65  lengths = new float[segmentCount];
66 
68 
69  startHandle = 2 * Points[0] - Points[1];
70  endHandle = 2 * Points[segmentCount] - Points[segmentCount - 1];
71 
72  Length = 0;
73  for (var i = 0; i < segmentCount; i++)
74  {
75  segments[i] = new CatmullRomCurve(
76  i == 0 ? startHandle : Points[i - 1],
77  Points[i],
78  Points[i + 1],
79  (i + 1) == segmentCount ? endHandle : Points[i + 2],
80  Alpha
81  );
82 
83  Length += segments[i].EstimateLength(n);
84  lengths[i] = Length;
85  }
86  }
87 
88  }
89 }
ARLocation.Spline.segmentCount
int segmentCount
The number of segments that make up the spline.
Definition: Spline.cs:28
ARLocation.CatmullRomSpline.CatmullRomSpline
CatmullRomSpline(Vector3[] points, int n, float alpha)
Creates a new Catmull-rom spline.
Definition: CatmullRomSpline.cs:48
ARLocation.Spline.segments
Curve[] segments
The CatmullRom curve-segments of the spline.
Definition: Spline.cs:23
ARLocation.Spline.Length
float Length
The full (estimated) length of the spline.
Definition: Spline.cs:33
ARLocation.CatmullRomCurve
A catmull-rom curve.
Definition: CatmullRomCurve.cs:9
ARLocation.CatmullRomSpline.Alpha
float Alpha
The alpha/tension parameter of the spline.
Definition: CatmullRomSpline.cs:27
ARLocation.CatmullRomSpline
A (open-ended) catmull-rom spline, which interpolates a set points by joining catmull-rom curves toge...
Definition: CatmullRomSpline.cs:11
ARLocation.Curve
Definition: Curve.cs:17
ARLocation.Spline
Definition: Spline.cs:13
ARLocation
Definition: ARLocationConfigInspector.cs:7
ARLocation.Spline.Points
Vector3[] Points
The points interpolated of the spline.
Definition: Spline.cs:18
ARLocation.CatmullRomSpline.CalculateSegments
sealed override void CalculateSegments(int n)
Calculate the catmull-rom segments. Also estimates the curve's length.
Definition: CatmullRomSpline.cs:60