Gorgon
Show / Hide Table of Contents

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 Source

GetInterpolatedValue(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 delta.

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 startPointIndex parameter is less than 0, or greater than/equal to the number of points in the spline minus 1.

ArgumentOutOfRangeException

[Debug only] Thrown when the startPointIndex is less than 0, or greater than/equal to the number of points - 1 in the Points parameter.

| Edit this page View Source

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 delta.

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.

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author