edu.neu.ccs.gui
Class Tangent

java.lang.Object
  extended byedu.neu.ccs.gui.Tangent

public class Tangent
extends Object

Class Tangent encapsulates an interface Strategy that defines the requirement for a strategy that can automatically use the vertex array and boundary information to generate the tangent array for Bezier curves.

Class Tangent also provides some examples of Strategy objects via factory methods and also makes their methods directly available as public static methods in the class to permit others to create Strategy objects.

Class Tangent cannot be instantiated.

Since:
2.3
Version:
2.3

Nested Class Summary
static interface Tangent.Strategy
          The Strategy interface requires methods that return the tangent array for a closed or open Bezier curve from its vertex array and, if needed, its end tangent data.
 
Field Summary
private static int maxTerms
          The maximum number of terms for which the bezierStrategy will be cached and the maximum number of terms needed to achieve practical smoothness.
private static int minTerms
          The minimum number of terms for which the bezierStrategy will be used.
private static Tangent.Strategy standardBezierStrategy
          The bezierStrategy cache.
 
Constructor Summary
private Tangent()
          Private constructor to prevent instantiation.
 
Method Summary
static float[] bezierCoefficients(int N, int terms)
          Returns the coefficients needed to compute the Bezier tangents corresponding to the length of the vertex data.
static Tangent.Strategy bezierStrategy()
          Returns the strategy that encapsulates the bezierTangents method using sufficient terms to guarantee second derviative smoothness in practical situations.
static Tangent.Strategy bezierStrategy(int terms)
          Returns the strategy that encapsulates the bezierTangents method using the given number of terms.
static float[][] bezierTangents(float[][] vertex, float[][] endTangent, int terms)
          Returns the unique Bezier tangents to make a smooth open cubic spline curve through the given vertex data and with the given endTangent data.
static float[][] bezierTangents(float[][] vertex, int terms)
          Returns the unique Bezier tangents to make a smooth closed cubic spline curve through the given vertex data.
static Tangent.Strategy chordStrategy(float factor)
          Returns the strategy that encapsulates the chordTangents method.
static float[][] chordTangents(float[][] vertex, float factor)
          Returns a tangent array for a closed cubic spline curve that is computed from the given vertex array by a chord-based strategy.
static float[][] chordTangents(float[][] vertex, float[][] endTangent, float factor)
          Returns a tangent array for an open cubic spline curve that is computed from the given vertex array and the given endTangent data by a chord-based strategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minTerms

private static final int minTerms
The minimum number of terms for which the bezierStrategy will be used.

See Also:
Constant Field Values

maxTerms

private static final int maxTerms
The maximum number of terms for which the bezierStrategy will be cached and the maximum number of terms needed to achieve practical smoothness.

See Also:
Constant Field Values

standardBezierStrategy

private static final Tangent.Strategy standardBezierStrategy
The bezierStrategy cache.

Constructor Detail

Tangent

private Tangent()
Private constructor to prevent instantiation.

Method Detail

bezierStrategy

public static Tangent.Strategy bezierStrategy()

Returns the strategy that encapsulates the bezierTangents method using sufficient terms to guarantee second derviative smoothness in practical situations.

In this implementation, the maximum number of terms used is 7.

See, Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in Andrew S. Glassner, Graphics Gems, Academic Press, 1990, 579-584.

Returns:
the strategy that encapsulates the bezierTangents method
See Also:
bezierStrategy(int), bezierTangents(float[][], int)

bezierStrategy

public static Tangent.Strategy bezierStrategy(int terms)

Returns the strategy that encapsulates the bezierTangents method using the given number of terms.

If terms < 1, then terms is set to 1.

See, Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in Andrew S. Glassner, Graphics Gems, Academic Press, 1990, 579-584.

Parameters:
terms - the maximum number of terms to use in computing each tangent
Returns:
the strategy that encapsulates the bezierTangents method
See Also:
bezierStrategy(), bezierTangents(float[][], int)

bezierTangents

public static float[][] bezierTangents(float[][] vertex,
                                       int terms)

Returns the unique Bezier tangents to make a smooth closed cubic spline curve through the given vertex data.

In this context smooth means that the first derivative is continuous at each vertex and the degree of continuity of the second derivative at each vertex is controlled by the number of terms used to compute the tangent.

If terms >= 7, then in practical situations, the second derivative will be continuous. Using a smaller value of terms will mean that fewer points affect the computation of the tangent at each vertex at the cost of some loss of continuity of the second derivative at each vertex.

Precondition: For some integer N >= 0:

Postcondition: For the same integer N:

If the vertex array fails its precondition then float[0][2] is returned.

If terms < 1, then terms is set to 1.

See, Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in Andrew S. Glassner, Graphics Gems, Academic Press, 1990, 579-584.

Parameters:
vertex - the vertex data
terms - the maximum number of terms to use in computing each tangent
Returns:
the associated smooth Bezier tangent data
See Also:
bezierStrategy(), bezierStrategy(int), bezierCoefficients(int, int)

bezierTangents

public static float[][] bezierTangents(float[][] vertex,
                                       float[][] endTangent,
                                       int terms)

Returns the unique Bezier tangents to make a smooth open cubic spline curve through the given vertex data and with the given endTangent data.

In this context smooth means that the first derivative is continuous at each vertex and the degree of continuity of the second derivative at each vertex is controlled by the number of terms used to compute the tangent.

If terms >= 7, then in practical situations, the second derivative will be continuous. Using a smaller value of terms will mean that fewer points affect the computation of the tangent at each vertex at the cost of some loss of continuity of the second derivative at each vertex.

Precondition 1. For some integer N >= 0:

Precondition 2.

Postcondition 1. For the same integer N:

Postcondition 2: If the endTangent array is null, then the function returns bezierTangents(vertex, terms). In other words, the fact that the curve is open is ignored.

Postcondition 3: If the endTangent array is non-null:

If the vertex array fails its precondition then float[0][2] is returned.

If the endTangent array fails its precondition then it is treated as if it were null.

If terms < 1, then terms is set to 1.

See, Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in Andrew S. Glassner, Graphics Gems, Academic Press, 1990, 579-584.

Parameters:
vertex - the vertex data
endTangent - the tangent data for the ends of the open curve
terms - the maximum number of terms to use in computing each tangent
Returns:
the associated smooth Bezier tangent data
See Also:
bezierStrategy(), bezierStrategy(int), bezierCoefficients(int, int)

bezierCoefficients

public static float[] bezierCoefficients(int N,
                                         int terms)

Returns the coefficients needed to compute the Bezier tangents corresponding to the length of the vertex data.

Note that: If length <= 2, returns the empty array: float[0]. For such a length, the coefficients are not in fact used in the algorithm.

If terms < 1, then terms is set to 1.

See, Richard Rasala, Explicit Cubic Spline Interpolation Formulas, in Andrew S. Glassner, Graphics Gems, Academic Press, 1990, 579-584.

Parameters:
N - the length of the vertex data array
terms - the maximum number of terms to use in computing each tangent
Returns:
the coefficients needed to compute the Bezier tangents
See Also:
bezierTangents(float[][], int)

chordStrategy

public static Tangent.Strategy chordStrategy(float factor)
Returns the strategy that encapsulates the chordTangents method.

Parameters:
factor - the fraction of the chord to use as the tangent
Returns:
the strategy that encapsulates the chordTangents method
See Also:
chordTangents(float[][], float)

chordTangents

public static float[][] chordTangents(float[][] vertex,
                                      float factor)

Returns a tangent array for a closed cubic spline curve that is computed from the given vertex array by a chord-based strategy.

Specifically, the rule for tangent computation is:

In this formula, we assume that indices wrap around at the ends of the vertex array.

This technique for computing the tangent array ensures that each tangent is influenced only by the two neighboring vertex points.

Precondition: For some integer N >= 0:

Postcondition: For the same integer N:

If the vertex array fails its precondition then float[0][2] is returned.

Parameters:
vertex - the vertex data
factor - the fraction of the chord to use as the tangent
Returns:
the associated tangent data
See Also:
chordStrategy(float)

chordTangents

public static float[][] chordTangents(float[][] vertex,
                                      float[][] endTangent,
                                      float factor)

Returns a tangent array for an open cubic spline curve that is computed from the given vertex array and the given endTangent data by a chord-based strategy.

Specifically, the rules for tangent computation are:

This technique for computing the tangent array ensures that each tangent is influenced only by the two neighboring vertex points.

Precondition 1. For some integer N >= 0:

Precondition 2.

Postcondition 1. For the same integer N:

Postcondition 2: If the endTangent array is null, then the function returns chordTangents(vertex, factor). In other words, the fact that the curve is open is ignored.

Postcondition 3: If the endTangent array is non-null:

If the vertex array fails its precondition then float[0][2] is returned.

If the endTangent array fails its precondition then it is treated as if it were null.

Parameters:
vertex - the vertex data
factor - the fraction of the chord to use as the tangent
Returns:
the associated tangent data
See Also:
chordStrategy(float)