A spline is defined by a series of points. These points may be of 2 or more dimensions. 2 dimensional splines may be displayed and edited using a gui. A LinearSpline interpolates between points using straight lines with no curvature.
points |
An array of points supplied as either Point objects or simple arrays. Points may have unlimited dimensions, though all points in a spline need to have the same number of dimensions. |
isClosed [boolean] |
If the spline's last point loops around to its first point. |
Interpolate points along the spline path. Note they are not evenly spaced along the whole path, but interpolate per segment. For a more common usage see bilinearInterpolate
divisions |
number of divisions per segment |
returns an array of points of size: (divisions * num segments)
While the interpolate method returns points spaced evenly along each segment of the spline, bilinearInterpolate returns points spaced evenly along one dimension. So if a spline is considered to be Y value varying over time as X, then bilinearInterpolate will return points along even time increments for use in buffers, routines that automate changing levels and for mapping function lookup tables.
divisions |
Number of points desired in the interpolated array |
domain |
The dimension number of the evenly spaced interpolation. Default is 0, which in the gui is seen as the X/horizontal dimension. |
fillEnds |
The interpolation will start at X value 0 and end at the last point. But your first point may not be at X=0. If fillEnds is true then the start of the interpolated array will be the first point repeated until the first point is reached. ( b = BSpline([ [ 0.42695473251029, 2.275 ], [ 1, 1 ], [ 2.5102880658436, 3.1 ], [ 4, 4 ] ]); b.gui; // to use X as time we need y values spaced in even X units d = b.bilinearInterpolate(512); d.plot2; ) |
an array of points, size=divisions
The bend in the road
If X is time, then time must of course march ever onwards.
If a spline point is to the left of a previous spline point then the spline path has travelled backwards in time
( b = BSpline([ [ 0, 2.5 ], [ 2.9044117647059, 1.225 ], [ 2.5275735294118, 2.8946875 ], [ 5.5836397058824, 4.58734375 ] ]); b.gui; b.bilinearInterpolate(512).plot2 )
So you can see that the interpolation which progresses always forward in time is bounded in the X dimension until the spline resumes travelling forward in the X direction.
Even if a point does not lie to the left of its left neighbor with certain curvature settings (in subclasses that have curvature):
( b = BSpline([ [ 0, 2.5 ], [ 2.9044117647059, 1.225 ], [ 3.1479779411765, 2.55125 ], [ 5.5836397058824, 4.58734375 ] ], 3.0); b.gui; b.bilinearInterpolate(512).plot2 )
then mapping along the X dimension can only yield one value for Y. That is always the first encountered value. This is to stop you from going back in time to kill your Grandfather.
In 3D this would be visibility: if the road curves to the left of the mountain, you cannot see it until it comes back out. In 3D rendering the area behind the curve would not be visible.
Create a new point, inserting it in the points array.
p |
The point, either as a Point object or as an array. |
i |
The point index to insert the point at. Note that the subsequent points are moved along the spline's point array but their values are not changed. |
delete a point
i |
index of the point to delete |
get/set the points array
get/set if the spline's last point loops around to its first point.
boolean
A closed loop:
LinearSpline( [ 0@0, 1@2.5,3@3],true).gui
Where value is a float index into the points array, interpolate a new point between points. This is used by the other interpolation methods.
u |
Float index into the points array |
a point array
the number of dimensions of the first point, assuming that all other points have the same dimensionality
For use by the gui, this returns the point array as Point objects, discarding any higher dimensions.
returns the min and max val of all points in the given dimension. Note that with subclasses that have curvature the min max returns only the points' min and max and does not account for curvature that may result in values above or below that in the final interpolation.
dim |
The dimension |
[minVal,maxVal]
Scale and normalize the points in that dimension to the requested min/max values. This moves the points, but note that subclasses which have curvature may result in values in teh interpolated spline that exceed min/max.
dim |
The dimension |
min |
min value |
max |
max value |
the normalization is in place, returns the same Spline object
concatenate another LinearSpline
thou |
the other spline |
a new LinearSpline
specifies the ObjectGui subclass which builds the GUI for editing the spline
ObjectGui subclass
(some example code)