Interface IGorgonSpline
Returns spline interpolated values across a set of points.
Inherited Members
Namespace: Gorgon.Math
Assembly: Gorgon.Core.dll
Syntax
public interface IGorgonSpline : IGorgonSplineCalculation
Remarks
This allows spline interpolation when iterating between points over time. This allows for a nice smoothing effect as a value approaches a node point on the spline.
Because this class provides smoothing between the nodes on the a spline, the result is very different than that of a linear interpolation. A linear interpolation will go in a straight line until the end point is reached. This can give a jagged looking effect when a point moves between several points that are in vastly different places. But the spline will smooth the transition for the value travelling to the destination points, thus giving a curved appearance when a point traverses the spline.
When adding or removing Points from the spline, remember to call UpdateTangents() to recalculate the tangents.
Examples
An example on how to use the spline object:
IGorgonSpline spline = new GorgonCatmullRomSpline();
spline.Points.Add(new Vector2(0, 0));
spline.Points.Add(new Vector2(1, 4.5f));
spline.Points.Add(new Vector2(7, -2.3f));
spline.Points.Add(new Vector2(10.2f, 0));
spline.UpdateTangents();
float startTime = GorgonTiming.SecondsSinceStart;
float endTime = GorgonTiming.SecondsSinceStart + 5;
float currentTime = 0;
while (currentTime < 1.0f)
{
Vector4 result = spline.GetInterpolatedValue(currentTime);
// Do something with the result... like plot a pixel:
// e.g PutPixel(result.X, result.Y, Color.Blue); or something.
// and over 5 seconds, a curved series of points should be plotted.
currentTime = GorgonTiming.SecondsSinceStart / (endTime - startTime);
}
Properties
| Edit this page View SourcePoints
Property to return the list of points for the spline.
Declaration
IList<Vector4> Points { get; }
Property Value
Type | Description |
---|---|
IList<Vector4> |
Remarks
When adding or removing points> from the spline, a call to the UpdateTangents() method is required to recalculate the tangents. Otherwise, the spline interpolation will be incorrect.
Methods
| Edit this page View SourceUpdateTangents()
Function to calculate the tangent vectors.
Declaration
void UpdateTangents()
Remarks
This function is used to calculate the tangent vectors from the points provided so that the object can interpolate a point in between the points given. Because this method requires the Points, it must be called whenever a change to the Points property is made.