fr.orsay.lri.varna.models
Class CubicBezierCurve

java.lang.Object
  extended by fr.orsay.lri.varna.models.CubicBezierCurve

public class CubicBezierCurve
extends Object

This class implements a cubic Bezier curve with a constant speed parametrization. The Bezier curve is approximated by a sequence of n straight lines, where the n+1 points between the lines are { B(k/n), k=0,1,...,n } where B is the standard parametrization given here: http://en.wikipedia.org/wiki/Bezier_curve#Cubic_B.C3.A9zier_curves You can then use the constant speed parametrization over this sequence of straight lines.

Author:
Raphael Champeimont

Field Summary
private  double[] lengths
          Array of length n.
private  int n
           
private  Point2D.Double P0
          The four points defining the curve.
private  Point2D.Double P1
          The four points defining the curve.
private  Point2D.Double P2
          The four points defining the curve.
private  Point2D.Double P3
          The four points defining the curve.
private  Point2D.Double[] points
          The n+1 points between the n lines.
private  Point2D.Double[] unitVectors
          Array of length n.
 
Constructor Summary
CubicBezierCurve(Point2D.Double P0, Point2D.Double P1, Point2D.Double P2, Point2D.Double P3, int n)
          A Bezier curve can be defined by four points, see http://en.wikipedia.org/wiki/Bezier_curve#Cubic_B.C3.A9zier_curves Here we give this four points and a integer to say in how many line segments we want to cut the Bezier curve (if n is bigger the computation takes longer but the precision is better).
 
Method Summary
private  void computeData()
           
 double getApproxCurveLength()
          Get the (exact) length of the approximation curve.
 int getN()
          The number of lines approximating the Bezier curve.
 Point2D.Double getP0()
           
 Point2D.Double getP1()
           
 Point2D.Double getP2()
           
 Point2D.Double getP3()
           
private  double lineLength(Point2D.Double P1, Point2D.Double P2)
           
 Point2D.Double standardParam(double t)
          The standard exact cubic Bezier curve parametrization.
 Point2D.Double[] uniformParam(double[] t)
          Uniform approximated parametrization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

P0

private Point2D.Double P0
The four points defining the curve.


P1

private Point2D.Double P1
The four points defining the curve.


P2

private Point2D.Double P2
The four points defining the curve.


P3

private Point2D.Double P3
The four points defining the curve.


n

private int n

points

private Point2D.Double[] points
The n+1 points between the n lines.


lengths

private double[] lengths
Array of length n. lengths[i] is the sum of lengths of lines up to and including the line starting at point points[i].


unitVectors

private Point2D.Double[] unitVectors
Array of length n. The vectors along each line, with a norm of 1.

Constructor Detail

CubicBezierCurve

public CubicBezierCurve(Point2D.Double P0,
                        Point2D.Double P1,
                        Point2D.Double P2,
                        Point2D.Double P3,
                        int n)
A Bezier curve can be defined by four points, see http://en.wikipedia.org/wiki/Bezier_curve#Cubic_B.C3.A9zier_curves Here we give this four points and a integer to say in how many line segments we want to cut the Bezier curve (if n is bigger the computation takes longer but the precision is better). The number of lines must be at least 1.

Method Detail

getN

public int getN()
The number of lines approximating the Bezier curve.


getApproxCurveLength

public double getApproxCurveLength()
Get the (exact) length of the approximation curve.


standardParam

public Point2D.Double standardParam(double t)
The standard exact cubic Bezier curve parametrization. Argument t must be in [0,1].


uniformParam

public Point2D.Double[] uniformParam(double[] t)
Uniform approximated parametrization. A value in t must be in [0, getApproxCurveLength()]. We have built a function f such that f(t) is the position of the point on the approximation curve (n straight lines). The interesting property is that the length of the curve { f(t), t in [0,l] } is exactly l. The java function is simply the application of f over each element of a sorted array, ie. uniformParam(t)[k] = f(t[k]). Computation time is O(n+m) where n is the number of lines in which the curve is divided and m is the length of the array given as an argument. The use of a sorted array instead of m calls to the function enables us to have a complexity of O(n+m) instead of O(n*m) because we don't need to search in all the n possible lines for each value in t (as we know their are in increasing order).


computeData

private void computeData()

lineLength

private double lineLength(Point2D.Double P1,
                          Point2D.Double P2)

getP0

public Point2D.Double getP0()

getP1

public Point2D.Double getP1()

getP2

public Point2D.Double getP2()

getP3

public Point2D.Double getP3()