Interface IGorgonSplineCalculation
Returns spline interpolated values across a set of points.
Namespace: Gorgon.Math
Assembly: Gorgon.Core.dll
Syntax
public interface 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.
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);
}
Methods
| Edit this page View SourceGetInterpolatedValue(int, float)
Function to return an interpolated point from the spline.
Declaration
Vector4 GetInterpolatedValue(int startPointIndex, float delta)
Parameters
Type | Name | Description |
---|---|---|
int | startPointIndex | Index in the point list to start from. |
float | delta | Delta value to interpolate. |
Returns
Type | Description |
---|---|
Vector4 | The interpolated value at |
Remarks
The delta
parameter is a unit value where 0 is the first point in the spline (relative to startPointIndex
) and 1 is the next point from the startPointIndex
in the spline.
If the delta
is less than 0, or greater than 1, the value will be wrapped to fit within the 0..1 range.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when the |
ArgumentOutOfRangeException |
|
GetInterpolatedValue(float)
Function to return an interpolated point from the spline.
Declaration
Vector4 GetInterpolatedValue(float delta)
Parameters
Type | Name | Description |
---|---|---|
float | delta | Delta value to interpolate. |
Returns
Type | Description |
---|---|
Vector4 | The interpolated value at |
Remarks
The delta
parameter is a unit value where 0 is the first point in the spline and 1.0 is the last point in the spline.
If the delta
is less than 0, or greater than 1, the value will be wrapped to fit within the 0..1 range.