sdr 0.7

net.cscott.sdr.util
Class Bezier.Bezier2D

java.lang.Object
  extended by net.cscott.sdr.util.Bezier.Bezier2D
Enclosing class:
Bezier

public static class Bezier.Bezier2D
extends Object

Bundle bezier parameters together into an object


Constructor Summary
Bezier.Bezier2D(Point... p)
           
 
Method Summary
 Point cp(int i)
          Return the specified control point.
 int degree()
          Return the degree of the Bezier curve, which is one less than the number of control points.
 Point evaluate(Fraction t)
          Evaluate the given Bezier at the given time parameter, which should be in the range [0, 1].
 double evaluateX(double t)
          Evaluate one dimension of the given Bezier in floating point.
 double evaluateY(double t)
          Evaluate one dimension of the given Bezier in floating point.
 Bezier.Bezier2D raise()
          Raise the degree of a bezier curve (add an additional control point).
 Bezier.Bezier2D tangent()
          Compute the derivative of the given Bezier curve.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bezier.Bezier2D

public Bezier.Bezier2D(Point... p)
Method Detail

degree

public int degree()
Return the degree of the Bezier curve, which is one less than the number of control points.


cp

public Point cp(int i)
Return the specified control point.


toString

public String toString()
Overrides:
toString in class Object

evaluate

public Point evaluate(Fraction t)
Evaluate the given Bezier at the given time parameter, which should be in the range [0, 1].


evaluateX

public double evaluateX(double t)
Evaluate one dimension of the given Bezier in floating point.


evaluateY

public double evaluateY(double t)
Evaluate one dimension of the given Bezier in floating point.


tangent

public Bezier.Bezier2D tangent()
Compute the derivative of the given Bezier curve.

Tests:
Derivative of a straight line is a constant:
js> p1 = new Point(Fraction.ZERO, Fraction.ONE);
0,1
js> p2 = new Point(Fraction.ONE, Fraction.ZERO);
1,0
js> b = new Bezier.Bezier2D(p1, p2);
[0,1, 1,0]
js> b.tangent()
[1,-1]
js> b.raise()
[0,1, 1/2,1/2, 1,0]
js> b.raise().tangent()
[1,-1, 1,-1]
More complicated tangent:
js> b = new Bezier.Bezier2D(new Point(Fraction.ZERO, Fraction.ZERO),
  >                         new Point(Fraction.ZERO, Fraction.ONE),
  >                         new Point(Fraction.ONE, Fraction.ONE),
  >                         new Point(Fraction.ONE, Fraction.ZERO));
[0,0, 0,1, 1,1, 1,0]
js> b.tangent()
[0,3, 3,0, 0,-3]

raise

public Bezier.Bezier2D raise()
Raise the degree of a bezier curve (add an additional control point).

Tests:
Basic interpolation of a straight line.
js> p1 = new Point(Fraction.ZERO, Fraction.ONE);
0,1
js> p2 = new Point(Fraction.ONE, Fraction.ZERO);
1,0
js> b = new Bezier.Bezier2D(p1, p2);
[0,1, 1,0]
js> b = b.raise()
[0,1, 1/2,1/2, 1,0]
js> b = b.raise()
[0,1, 1/3,2/3, 2/3,1/3, 1,0]
js> b = b.raise()
[0,1, 1/4,3/4, 1/2,1/2, 3/4,1/4, 1,0]
With enough iterations, the control polygon begins to approximate the curve.
js> b = new Bezier.Bezier2D(new Point(Fraction.ZERO, Fraction.ZERO),
  >                         new Point(Fraction.ZERO, Fraction.ONE),
  >                         new Point(Fraction.ONE, Fraction.ONE),
  >                         new Point(Fraction.ONE, Fraction.ZERO));
[0,0, 0,1, 1,1, 1,0]
js> b = b.raise();
[0,0, 0,3/4, 1/2,1, 1,3/4, 1,0]
js> b = b.raise();
[0,0, 0,3/5, 3/10,9/10, 7/10,9/10, 1,3/5, 1,0]
js> b = b.raise();
[0,0, 0,1/2, 1/5,4/5, 1/2,9/10, 4/5,4/5, 1,1/2, 1,0]
js> b = b.raise();
[0,0, 0,3/7, 1/7,5/7, 13/35,6/7, 22/35,6/7, 6/7,5/7, 1,3/7, 1,0]

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian