## toxi.geom Class Spline2D

```java.lang.Object toxi.geom.Spline2D
```

`public class Spline2Dextends java.lang.Object` This is a generic 3D B-Spline class for curves of arbitrary length, control handles and patches are created and joined automatically as described here: ibiblio.org/e-notes/ Splines/Bint.htm

Thanks to a bug report by Aaron Meyers (http://universaloscillation.com) the computeVertices(int) method has a slightly changed behaviour from version 0014 onwards. In earlier versions erroneous duplicate points would be added near each given control point, which lead to various weird results.

The new behaviour of the curve interpolation/computation is described in the docs for the computeVertices(int) method below.

Field Summary
` BernsteinPolynomial` `bernstein`

` float[]` `bi`

` Vec2D[]` `coeffA`

`static int` `DEFAULT_RES`

`static float` `DEFAULT_TIGHTNESS`

` Vec2D[]` `delta`

` java.util.List<Vec2D>` `pointList`

` java.util.List<Vec2D>` `vertices`

Constructor Summary
`Spline2D()`
Constructs an empty spline container with default curve tightness.
`Spline2D(java.util.List<Vec2D> rawPoints)`

```Spline2D(java.util.List<Vec2D> rawPoints, BernsteinPolynomial b, float tightness)```

`Spline2D(Vec2D[] pointArray)`

```Spline2D(Vec2D[] pointArray, BernsteinPolynomial b, float tightness)```

Method Summary
` Spline2D` ```add(float x, float y)```

` Spline2D` `add(ReadonlyVec2D p)`
Adds the given point to the list of control points.
` java.util.List<Vec2D>` `computeVertices(int res)`
Computes all curve vertices based on the resolution/number of subdivisions requested.
` java.util.List<Vec2D>` `getDecimatedVertices(float step)`
Computes a list of points along the spline which are uniformly separated by the given step distance.
` java.util.List<Vec2D>` ```getDecimatedVertices(float step, boolean doAddFinalVertex)```
Computes a list of points along the spline which are uniformly separated by the given step distance.
` float` `getEstimatedArcLength()`

` int` `getNumPoints()`
Returns the number of key points.
` java.util.List<Vec2D>` `getPointList()`

` float` `getTightness()`

` Spline2D` `setPointList(java.util.List<Vec2D> plist)`
Overrides the current control points with the given list.
` Spline2D` `setTightness(float tightness)`
Sets the tightness for future curve interpolation calls.
` void` `updateCoefficients()`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_TIGHTNESS

`public static final float DEFAULT_TIGHTNESS`
Constant Field Values

### DEFAULT_RES

`public static final int DEFAULT_RES`
Constant Field Values

### pointList

`public java.util.List<Vec2D> pointList`

### vertices

`public java.util.List<Vec2D> vertices`

### bernstein

`public BernsteinPolynomial bernstein`

### delta

`public Vec2D[] delta`

### coeffA

`public Vec2D[] coeffA`

### bi

`public float[] bi`
Constructor Detail

### Spline2D

`public Spline2D()`
Constructs an empty spline container with default curve tightness. You need to populate the spline manually by using `add(ReadonlyVec2D)` .

### Spline2D

`public Spline2D(java.util.List<Vec2D> rawPoints)`
Parameters:
`rawPoints` - list of control point vectors

### Spline2D

```public Spline2D(java.util.List<Vec2D> rawPoints,
BernsteinPolynomial b,
float tightness)```
Parameters:
`rawPoints` - list of control point vectors
`b` - predefined Bernstein polynomial (good for reusing)
`tightness` - default curve tightness used for the interpolated vertices setTightness(float)

### Spline2D

`public Spline2D(Vec2D[] pointArray)`
Parameters:
`pointArray` - array of control point vectors

### Spline2D

```public Spline2D(Vec2D[] pointArray,
BernsteinPolynomial b,
float tightness)```
Parameters:
`pointArray` - array of control point vectors
`b` - predefined Bernstein polynomial (good for reusing)
`tightness` - default curve tightness used for the interpolated vertices setTightness(float)
Method Detail

```public Spline2D add(float x,
float y)```

`public Spline2D add(ReadonlyVec2D p)`
Adds the given point to the list of control points.

Parameters:
`p` -
Returns:
itself

### computeVertices

`public java.util.List<Vec2D> computeVertices(int res)`

Computes all curve vertices based on the resolution/number of subdivisions requested. The higher, the more vertices are computed:

(number of control points - 1) * resolution + 1

Since version 0014 the automatic placement of the curve handles can also be manipulated via the setTightness(float) method.

Parameters:
`res` - the number of vertices to be computed per segment between original control points (incl. control point always at the start of each segment)
Returns:
list of Vec2D vertices along the curve

### getDecimatedVertices

`public java.util.List<Vec2D> getDecimatedVertices(float step)`
Computes a list of points along the spline which are uniformly separated by the given step distance.

Parameters:
`step` -
Returns:
point list

### getDecimatedVertices

```public java.util.List<Vec2D> getDecimatedVertices(float step,
Computes a list of points along the spline which are uniformly separated by the given step distance.

Parameters:
`step` -
`doAddFinalVertex` - true, if the last vertex computed by `computeVertices(int)` should be added regardless of its distance.
Returns:
point list

### getEstimatedArcLength

`public float getEstimatedArcLength()`
Returns:
estimated arc length based on summing the individual lengths of the line segments computed with `computeVertices(int)`.

### getNumPoints

`public int getNumPoints()`
Returns the number of key points.

Returns:
the numP

### getPointList

`public java.util.List<Vec2D> getPointList()`
Returns:
the pointList

### getTightness

`public float getTightness()`
Returns:
the spline3d tightness
Since:
0014 (rev.216)
`setTightness(float)`

### setPointList

`public Spline2D setPointList(java.util.List<Vec2D> plist)`
Overrides the current control points with the given list.

Parameters:
`plist` -
Returns:
itself

### setTightness

`public Spline2D setTightness(float tightness)`
Sets the tightness for future curve interpolation calls. Default value is 0.25. A value of 0.0 equals linear interpolation between the given curve input points. Curve behaviour for values outside the 0.0 .. 0.5 interval is unspecified and becomes increasingly less intuitive. Negative values are possible too and create interesting results (in some cases).

Parameters:
`tightness` - the tightness value used for the next call to `computeVertices(int)`
Since:
0014 (rev. 216)

### updateCoefficients

`public void updateCoefficients()`