org.openmali.curves
Class CubicBezierSpline

java.lang.Object
  extended by org.openmali.curves.CubicBezierSpline

public class CubicBezierSpline
extends java.lang.Object

A cubic Bezier Curve (degree 3)


Constructor Summary
CubicBezierSpline(Tuple3f[] points)
          Constructs a Bézier Spline with composed of cubic Bézier curves.
CubicBezierSpline(Tuple3f[] basePoints, Tuple3f[] controlPoints)
          Constructs a Bézier Spline with composed of cubic Bézier curves.
 
Method Summary
 void addBasePoint(int index, Tuple3f point)
          Adds a new Point at the specified index and shifts the already exiting points one index further.
 void addBasePoint(Tuple3f point)
          Adds a new Point into the nearest spline segment.
 float closestParameter(float x, float y, float z)
          Computes the paramter that would give the closest point on this spline to the given point.
 float closestParameter(Tuple3f p)
          Computes the paramter that would give the closest point on this spline to the given point.
 int closestPoint(float x, float y, float z, Tuple3f resultPoint)
          Computes the point on this spline that is closest to the given point.
 int closestPoint(float x, float y, float z, Tuple3f resultPoint, Tuple2f resultParams)
          Computes the point on this spline that is closest to the given point.
 int closestPoint(Tuple3f point, Tuple3f resultPoint)
          Computes the point on this spline that is closest to the given point.
 int closestPoint(Tuple3f point, Tuple3f resultPoint, Tuple2f resultParams)
          Computes the point on this spline that is closest to the given point.
 int closestSubcurve(float x, float y, float z)
          Finds the index of the subcurve with the point, that is closest to the given point.
 int closestSubcurve(Tuple3f point)
          Finds the index of the subcurve with the point, that is closest to the given point.
static Point3f evalPoint(Tuple3f p0, Tuple3f p1, Tuple3f p2, Tuple3f p3, float t)
           
static
<P extends Tuple3f>
P
evalPoint(Tuple3f p0, Tuple3f p1, Tuple3f p2, Tuple3f p3, float t, P p)
           
static Point3f[] evalPoints(Tuple3f p0, Tuple3f p1, Tuple3f p2, Tuple3f p3, int numPoints)
           
static Point3f[] evalPoints(Tuple3f p0, Tuple3f p1, Tuple3f p2, Tuple3f p3, Point3f[] result)
           
static Tuple3f[] evalPoints(Tuple3f p0, Tuple3f p1, Tuple3f p2, Tuple3f p3, Tuple3f[] result)
           
 void generateControlPoints(int start, int end)
          Generates control points for the given base point range.
 Point3f getBasePoint(int n)
           
 Point3f[] getBasePoints()
           
 Point3f getControlPoint(int n)
           
 Point3f[] getControlPoints()
           
 float getLength()
           
 java.util.List<Point3f> getPoints()
           
 Point3f samplePoint(float t)
           
<P extends Tuple3f>
P
samplePoint(float s, P p)
           
 Point3f[] samplePoints(int numPoints)
           
 Point3f[] samplePoints(Point3f[] result)
           
 Tuple3f[] samplePoints(Tuple3f[] result)
           
 float squaredDistanceTo(float x, float y, float z)
          Computes the nearest distance between this spline and a point
 float squaredDistanceTo(Tuple3f p)
          Computes the nearest distance between this spline and a point
 void update()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CubicBezierSpline

public CubicBezierSpline(Tuple3f[] points)
Constructs a Bézier Spline with composed of cubic Bézier curves.

Parameters:
points -

CubicBezierSpline

public CubicBezierSpline(Tuple3f[] basePoints,
                         Tuple3f[] controlPoints)
Constructs a Bézier Spline with composed of cubic Bézier curves.

Parameters:
basePoints -
controlPoints -
Method Detail

getLength

public float getLength()

getBasePoints

public final Point3f[] getBasePoints()
Returns:
the array of base-points for this Bézier Spline.

getBasePoint

public Point3f getBasePoint(int n)
Returns:
the n-th base-point for this Bézier Spline.

addBasePoint

public void addBasePoint(Tuple3f point)
Adds a new Point into the nearest spline segment. The control points will be generated automatically.

Parameters:
point - the coordinates of the new point

addBasePoint

public void addBasePoint(int index,
                         Tuple3f point)
Adds a new Point at the specified index and shifts the already exiting points one index further. The control points will be generated automatically.

Parameters:
index - the index to add the point
point - the coordinates of the new point

getControlPoints

public final Point3f[] getControlPoints()
Returns:
the array of base-points for this Bézier Spline.

getControlPoint

public Point3f getControlPoint(int n)
Returns:
the n-th control-point for this Bézier Spline.

getPoints

public java.util.List<Point3f> getPoints()

evalPoint

public static <P extends Tuple3f> P evalPoint(Tuple3f p0,
                                              Tuple3f p1,
                                              Tuple3f p2,
                                              Tuple3f p3,
                                              float t,
                                              P p)

evalPoint

public static Point3f evalPoint(Tuple3f p0,
                                Tuple3f p1,
                                Tuple3f p2,
                                Tuple3f p3,
                                float t)

evalPoints

public static Tuple3f[] evalPoints(Tuple3f p0,
                                   Tuple3f p1,
                                   Tuple3f p2,
                                   Tuple3f p3,
                                   Tuple3f[] result)
Parameters:
result - result.length Point3fs from the Bézier Curve

evalPoints

public static final Point3f[] evalPoints(Tuple3f p0,
                                         Tuple3f p1,
                                         Tuple3f p2,
                                         Tuple3f p3,
                                         Point3f[] result)
Parameters:
result - result.length Point3fs from the Bézier Curve

evalPoints

public static Point3f[] evalPoints(Tuple3f p0,
                                   Tuple3f p1,
                                   Tuple3f p2,
                                   Tuple3f p3,
                                   int numPoints)
Parameters:
numPoints -
Returns:
numPoints * Point3f from the Bézier curve

samplePoint

public <P extends Tuple3f> P samplePoint(float s,
                                         P p)
Parameters:
s - with 0 <= s <= 1
p - the point output object to write the calculated point on the Bézier Spline to

samplePoint

public final Point3f samplePoint(float t)
Parameters:
t - with 0 < t < 1
Returns:
one point on the Bézier Spline

samplePoints

public Tuple3f[] samplePoints(Tuple3f[] result)
Parameters:
result - result.length Point3fs from the Bézier Curve

samplePoints

public final Point3f[] samplePoints(Point3f[] result)
Parameters:
result - result.length Point3fs from the Bézier Curve

samplePoints

public Point3f[] samplePoints(int numPoints)
Parameters:
numPoints -
Returns:
numPoints * Point3f from the Bézier curve

update

public void update()

generateControlPoints

public void generateControlPoints(int start,
                                  int end)
Generates control points for the given base point range. The range is given by indices from start (inclusive) to end (exclusive).

Parameters:
start - the first basePoint to generate control points for
end - the first basePoint _not_ to generate control points for

closestPoint

public int closestPoint(float x,
                        float y,
                        float z,
                        Tuple3f resultPoint,
                        Tuple2f resultParams)
Computes the point on this spline that is closest to the given point. Additionally it computes the subcurve the point is on, the spline-equation parameter and the squared distance between the two points

Parameters:
x - X coordinate of the point to test
y - Y coordinate of the point to test
z - Z coordinate of the point to test
resultPoint - will contain the point on this spline that is closest to the given point
resultParams - will contain the spline-equation parameter as x and the squared distance as y
Returns:
the subcurve, the closest point lies on.

closestPoint

public int closestPoint(Tuple3f point,
                        Tuple3f resultPoint,
                        Tuple2f resultParams)
Computes the point on this spline that is closest to the given point. Additionally it computes the subcurve the point is on, the spline-equation parameter and the squared distance between the two points

Parameters:
point - the point to test
resultPoint - will contain the point on this spline that is closest to the given point
resultParams - will contain the spline-equation parameter as x and the squared distance as y
Returns:
the subcurve, the closest point lies on.

closestPoint

public int closestPoint(float x,
                        float y,
                        float z,
                        Tuple3f resultPoint)
Computes the point on this spline that is closest to the given point.

Parameters:
x - X coordinate of the point to test
y - Y coordinate of the point to test
z - Z coordinate of the point to test
resultPoint - will contain the point on this spline that is closest to the given point
Returns:
the subcurve, the closest point lies on.

closestPoint

public int closestPoint(Tuple3f point,
                        Tuple3f resultPoint)
Computes the point on this spline that is closest to the given point.

Parameters:
point - the point to test
resultPoint - will contain the point on this spline that is closest to the given point
Returns:
the subcurve, the closest point lies on.

closestSubcurve

public int closestSubcurve(float x,
                           float y,
                           float z)
Finds the index of the subcurve with the point, that is closest to the given point.

Parameters:
x - X coordinate of the point to test
y - Y coordinate of the point to test
z - Z coordinate of the point to test
Returns:
the index of the line segment formed by basePoint[index] and basePoint[index+1]

closestSubcurve

public int closestSubcurve(Tuple3f point)
Finds the index of the subcurve with the point, that is closest to the given point.

Parameters:
point - the point to test
Returns:
the index of the line segment formed by basePoint[index] and basePoint[index+1]

closestParameter

public float closestParameter(float x,
                              float y,
                              float z)
Computes the paramter that would give the closest point on this spline to the given point.

Parameters:
x - X coordinate of a point
y - Y coordinate of a point
z - Z coordinate of a point
Returns:
the parameter that can be feed to samplePoint() to get the nearest point on this spline

closestParameter

public float closestParameter(Tuple3f p)
Computes the paramter that would give the closest point on this spline to the given point.

Parameters:
p - the coordinates of a point
Returns:
the parameter that can be feed to samplePoint() to get the nearest point on this spline

squaredDistanceTo

public float squaredDistanceTo(float x,
                               float y,
                               float z)
Computes the nearest distance between this spline and a point

Parameters:
x - X coordinate of a point
y - Y coordinate of a point
z - Z coordinate of a point
Returns:
the distance between the point and the spline

squaredDistanceTo

public float squaredDistanceTo(Tuple3f p)
Computes the nearest distance between this spline and a point

Parameters:
p - the coordinates of a point
Returns:
the distance between the point and the spline