data
Class Curve

java.lang.Object
  extended bydata.Curve

public class Curve
extends Object

This class represents a Bezier curve. It has 4 control points, and is able to determine the position in the curve at a given t.

Since:
1.00
Version:
1.10
Author:
Berend "Kirk" Wouda

Field Summary
protected  ControlPoint[] cparray
          The array of ControlPoints.
 
Constructor Summary
Curve(ControlPoint cp1, ControlPoint cp2, ControlPoint cp3, ControlPoint cp4)
          Creates a new Curve with the 4 given ControlPoints.
 
Method Summary
 double calculateX(double t)
          Calculates and returns the X coordinate of the function at the specified time t by using the Bezier formula: x = x0 * (1-t)^3 + 3 * x1 * t * (1-t)^2 + 3 * x2 * t^2 * (1-t) + x3 * t^3
 double calculateY(double t)
          Calculates and returns the Y coordinate of the function at the specified time t by using the Bezier formula: y = y0 * (1-t)^3 + 3 * y1 * t * (1-t)^2 + 3 * y2 * t^2 * (1-t) + y3 * t^3
 ControlPoint getControlPoint(int index)
          Returns the ControlPoint identified by P(index) as in the Bezier formula.
 void setControlPoint(int index, ControlPoint cp)
          Sets the ControlPoint at index (identified by P(index) as in the Bezier formula) of this Curve to the given ControlPoint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cparray

protected ControlPoint[] cparray
The array of ControlPoints.

Constructor Detail

Curve

public Curve(ControlPoint cp1,
             ControlPoint cp2,
             ControlPoint cp3,
             ControlPoint cp4)
Creates a new Curve with the 4 given ControlPoints.

Parameters:
cp1 - The first ControlPoint.
cp2 - The second ControlPoint.
cp3 - The third ControlPoint.
cp4 - The fourth ControlPoint.
Method Detail

getControlPoint

public ControlPoint getControlPoint(int index)
Returns the ControlPoint identified by P(index) as in the Bezier formula.

Parameters:
index - The index of the ControlPoint you want. Must be between 0 and 3, inclusive.
Returns:
The ControlPoint at index.

setControlPoint

public void setControlPoint(int index,
                            ControlPoint cp)
Sets the ControlPoint at index (identified by P(index) as in the Bezier formula) of this Curve to the given ControlPoint.

Parameters:
index - The index of the ControlPoint you want to set. Must be between 0 and 3, inclusive.
cp - The ControlPoint you want to set.

calculateX

public double calculateX(double t)

Calculates and returns the X coordinate of the function at the specified time t by using the Bezier formula:

x = x0 * (1-t)^3 + 3 * x1 * t * (1-t)^2 + 3 * x2 * t^2 * (1-t) + x3 * t^3

Parameters:
t - The time parameter for the Bezier formula. Must be within 0 and 1, inclusive.
Returns:
The X coordinate at time t.

calculateY

public double calculateY(double t)

Calculates and returns the Y coordinate of the function at the specified time t by using the Bezier formula:

y = y0 * (1-t)^3 + 3 * y1 * t * (1-t)^2 + 3 * y2 * t^2 * (1-t) + y3 * t^3

Parameters:
t - The time parameter for the Bezier formula. Must be within 0 and 1, inclusive.
Returns:
The Y coordinate at time t.