## edu.neu.ccs.util Class Bezier

```java.lang.Object
edu.neu.ccs.util.Bezier
```

public class Bezier
extends Object

The class `Bezier` collects several useful static mathematical functions related to Bezier curves. All of the functions deal with control points that are a single float number. In applications, these functions would be used for each coordinate in a geometric point, that is, for the x, y, and possibly z coordinates. Thus, the functions would be used 2 or 3 times, once for each coordinate in a 2 or 3 dimensional geometric point.

In Java Power Tools, these functions are used in class `PathList` in the `getShapePoint` method. This is one example of their usefulness.

One mathematical reference for this material is:

Gerald Farin

Curves and Surfaces for Computer Aided Geometric Design: A Practical Guide

Convention: functions for `float` data are appended with `F` and functions for `double` data are appended with `D`.

Since:
2.4.0

 Constructor Summary `Bezier()`

 Method Summary `static double` ```bezierD(double t, double x0)```           The trivial `double` Bezier polynomial of degree 0 that returns `x0`. `static double` ```bezierD(double t, double[] array, int a, int b)```           This version of the Bezier polynomial uses the given polynomial parameter t, the given array of control points, and a pair of index values a and b with a <= b that define the range used in array for the computation; the function returns the Bezier for the given data. `static double` ```bezierD(double t, double x0, double x1)```           The `double` Bezier polynomial of degree 1 that returns the interpolation of x0 and x1 relative to t. `static double` ```bezierD(double t, double x0, double x1, double x2)```           The `double` Bezier polynomial of degree 2 that returns the interpolation of the next pair of lower Bezier's relative to t. `static double` ```bezierD(double t, double x0, double x1, double x2, double x3)```           The `double` Bezier polynomial of degree 3 that returns the interpolation of the next pair of lower Bezier's relative to t. `static float` ```bezierF(float t, float x0)```           The trivial `float` Bezier polynomial of degree 0 that returns `x0`. `static float` ```bezierF(float t, float[] array, int a, int b)```           This version of the Bezier polynomial uses the given polynomial parameter t, the given array of control points, and a pair of index values a and b with a <= b that define the range used in array for the computation; the function returns the Bezier for the given data. `static float` ```bezierF(float t, float x0, float x1)```           The `float` Bezier polynomial of degree 1 that returns the interpolation of x0 and x1 relative to t. `static float` ```bezierF(float t, float x0, float x1, float x2)```           The `float` Bezier polynomial of degree 2 that returns the interpolation of the next pair of lower Bezier's relative to t. `static float` ```bezierF(float t, float x0, float x1, float x2, float x3)```           The `float` Bezier polynomial of degree 3 that returns the interpolation of the next pair of lower Bezier's relative to t. `static double[]` ```mapBezierD(double t, double[] array)```           This function maps the function `BezierD` of three arguments across the given array and produces a new array with size one less than the original array. `static float[]` ```mapBezierF(float t, float[] array)```           This function maps the function `BezierF` of three arguments across the given array and produces a new array with size one less than the original array. `static double[]` ```newBezierPointsD(double a, double b, double[] controls)```           This function computes a new set of control points as if the Bezier polynomial defined by the given control points were to be viewed as on the sub-interval [a;b] of [0;1]. `static float[]` ```newBezierPointsF(float a, float b, float[] controls)```           This function computes a new set of control points as if the Bezier polynomial defined by the given control points were to be viewed as on the sub-interval [a;b] of [0;1].

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

 Constructor Detail

### Bezier

`public Bezier()`
 Method Detail

### bezierF

```public static float bezierF(float t,
float x0)```
The trivial `float` Bezier polynomial of degree 0 that returns `x0`.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0

### bezierF

```public static float bezierF(float t,
float x0,
float x1)```

The `float` Bezier polynomial of degree 1 that returns the interpolation of x0 and x1 relative to t.

In formulas, returns:

`  (1-t)*x0 + t*x1`

The Bezier of degree 1 is used to compute points on a line.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1

### bezierF

```public static float bezierF(float t,
float x0,
float x1,
float x2)```

The `float` Bezier polynomial of degree 2 that returns the interpolation of the next pair of lower Bezier's relative to t.

In formulas, returns:

`  (1-t)*bezierF(t, x0, x1) + t*bezierF(t, x1, x2)`

The Bezier of degree 2 is used to compute points on a quadratic Bezier curve.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1
`x2` - control point 2

### bezierF

```public static float bezierF(float t,
float x0,
float x1,
float x2,
float x3)```

The `float` Bezier polynomial of degree 3 that returns the interpolation of the next pair of lower Bezier's relative to t.

In formulas, returns:

`  (1-t)*bezierF(t, x0, x1, x2) + t*bezierF(t, x1, x2, x3)`

The Bezier of degree 3 is used to compute points on a cubic Bezier curve.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1
`x2` - control point 2
`x3` - control point 3

### bezierF

```public static float bezierF(float t,
float[] array,
int a,
int b)```

This version of the Bezier polynomial uses the given polynomial parameter t, the given array of control points, and a pair of index values a and b with a <= b that define the range used in array for the computation; the function returns the Bezier for the given data.

The precise preconditions are:

• The `array` is non-`null`
• `0 <= a <= b < array.length`

Returns 0 if the preconditions fail.

If a equals b, returns `array[a]` independent of t.

Otherwise, returns the following recursive value.

`  bezierF(t, bezierF(t,array,a,b-1), bezierF(t,array,a+1,b))`

Parameters:
`t` - the polynomial parameter
`array` - the control point array
`a` - the start index
`b` - the final index

### mapBezierF

```public static float[] mapBezierF(float t,
float[] array)```

This function maps the function `BezierF` of three arguments across the given array and produces a new array with size one less than the original array.

First assume that the length N of the given array is at least 2 so the result array has length (N-1) that is at least 1. Then, the i-th entry in the result array is computed as follows:

`  bezierF(t, array[i], array[i+1])`

If the given array has length 0 or 1, returns the trivial array `new float[0]`.

If the given array is `null`, then returns `null`.

This is a helper method for the `newBezierPointsF` method.

Parameters:
`t` - the interpolation parameter
`array` - the array to be mapped with bezierF

### newBezierPointsF

```public static float[] newBezierPointsF(float a,
float b,
float[] controls)```

This function computes a new set of control points as if the Bezier polynomial defined by the given control points were to be viewed as on the sub-interval [a;b] of [0;1].

This function is useful for finding the control points for a curve that is restricted to a sub-interval of its parameter space [0;1].

If a equals 0 and b equals 1 then returns a copy of the given control points (up to round off).

If b < a, the direction of the new Bezier is opposite to the original direction.

If a or b is outside of [0;1] then the result is correct but will involve more round off error since extrapolation is used.

This method implements the 1 dimensional heart of what is known as the generalized deCasteljau algorithm. See section 7.3 of the book by Farin mentioned in the introduction for details and a discussion of why the algorithm is correct.

Parameters:
`a` - float endpoint 1 in a sub-interval
`b` - float endpoint 2 in a sub-interval
`controls` - the original array of Bezier control points

### bezierD

```public static double bezierD(double t,
double x0)```
The trivial `double` Bezier polynomial of degree 0 that returns `x0`.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0

### bezierD

```public static double bezierD(double t,
double x0,
double x1)```

The `double` Bezier polynomial of degree 1 that returns the interpolation of x0 and x1 relative to t.

In formulas, returns:

`  (1-t)*x0 + t*x1`

The Bezier of degree 1 is used to compute points on a line.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1

### bezierD

```public static double bezierD(double t,
double x0,
double x1,
double x2)```

The `double` Bezier polynomial of degree 2 that returns the interpolation of the next pair of lower Bezier's relative to t.

In formulas, returns:

`  (1-t)*bezierF(t, x0, x1) + t*bezierF(t, x1, x2)`

The Bezier of degree 2 is used to compute points on a quadratic Bezier curve.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1
`x2` - control point 2

### bezierD

```public static double bezierD(double t,
double x0,
double x1,
double x2,
double x3)```

The `double` Bezier polynomial of degree 3 that returns the interpolation of the next pair of lower Bezier's relative to t.

In formulas, returns:

`  (1-t)*bezierF(t, x0, x1, x2) + t*bezierF(t, x1, x2, x3)`

The Bezier of degree 3 is used to compute points on a cubic Bezier curve.

Parameters:
`t` - the polynomial parameter
`x0` - control point 0
`x1` - control point 1
`x2` - control point 2
`x3` - control point 3

### bezierD

```public static double bezierD(double t,
double[] array,
int a,
int b)```

This version of the Bezier polynomial uses the given polynomial parameter t, the given array of control points, and a pair of index values a and b with a <= b that define the range used in array for the computation; the function returns the Bezier for the given data.

The precise preconditions are:

• The `array` is non-`null`
• `0 <= a <= b < array.length`

Returns 0 if the preconditions fail.

If a equals b, returns `array[a]` independent of t.

Otherwise, returns the following recursive value.

`  bezierD(t, bezierD(t,array,a,b-1), bezierD(t,array,a+1,b))`

Parameters:
`t` - the polynomial parameter
`array` - the control point array
`a` - the start index
`b` - the final index

### mapBezierD

```public static double[] mapBezierD(double t,
double[] array)```

This function maps the function `BezierD` of three arguments across the given array and produces a new array with size one less than the original array.

First assume that the length N of the given array is at least 2 so the result array has length (N-1) that is at least 1. Then, the i-th entry in the result array is computed as follows:

`  bezierD(t, array[i], array[i+1])`

If the given array has length 0 or 1, returns the trivial array `new double[0]`.

If the given array is `null`, then returns `null`.

This is a helper method for the `newBezierPointsD` method.

Parameters:
`t` - the interpolation parameter
`array` - the array to be mapped with bezierD

### newBezierPointsD

```public static double[] newBezierPointsD(double a,
double b,
double[] controls)```

This function computes a new set of control points as if the Bezier polynomial defined by the given control points were to be viewed as on the sub-interval [a;b] of [0;1].

This function is useful for finding the control points for a curve that is restricted to a sub-interval of its parameter space [0;1].

If a equals 0 and b equals 1 then returns a copy of the given control points (up to round off).

If b < a, the direction of the new Bezier is opposite to the original direction.

If a or b is outside of [0;1] then the result is correct but will involve more round off error since extrapolation is used.

This method implements the 1 dimensional heart of what is known as the generalized deCasteljau algorithm. See section 7.3 of the book by Farin mentioned in the introduction.

Parameters:
`a` - double endpoint 1 in a sub-interval
`b` - double endpoint 2 in a sub-interval
`controls` - the original array of Bezier control points