org.proteinshader.math
Class Hermite

java.lang.Object
  extended by org.proteinshader.math.Hermite

public class Hermite
extends Object

Calculates a cubic equation between two control points so that points on the curve in between can be interpolated.

To use Hermite interpolation, the xyz-coordinate and tangent must be known for both the start point and the end point. Three separate cubic equations will be determined: one for the x dimension, one for the y dimension, and one for the z dimension. The free variable in each cubic equation is the parameter t. The parameter t is 0.0 for the start point and 1.0 for the end point. Once the constants for the cubic equations have been determined, a parameter t between 0.0 and 1.0 can be plugged in to get the xyz-coordinate and tangent of any point on the curve between the start and end points.

The equations shown below are for calculating the y dimension, but the exact same math applies to the x and z dimensions. These equations can be found on pages 643-645 of 'Computer Graphics Using OpenGL' by F.S. Hill, 2nd Edition (2001).

Cubic equation for y: y(t) = Ay*t^3 + By*t^2 + Cy*t + Dy


First derivative for y: y(t) = 3Ay*t^2 + 2By*t + Cy


Input values for Hermite interpolation:
p1.y - the y-value at the start point
p2.y - the y-value at the end point
tan1.y - the y-value of the tangent at the start point
tan2.y - the y-value of the tangent at the end point


Solutions for the coefficients of the cubic equation:
Ay = tan2.y + tan1.y - 2(p2.y - p1.y)
By = 3(p2.y - p1.y) - 2tan1.y - tan2.y
Cy = tan1.y
Dy = p1.y


Constructor Summary
Hermite(Point3d p1, Point3d p2, Vec3d tan1, Vec3d tan2)
          Constructs a Hermite object by using the input points and vectors to calculate and store the coefficients needed for the cubic equations for x(t), y(t), and z(t).
Hermite(Vec3d p1, Vec3d p2, Vec3d tan1, Vec3d tan2)
          Constructs a Hermite object by using the input vectors to calculate and store the coefficients needed for the cubic equations for x(t), y(t), and z(t).
 
Method Summary
 Point3d calculatePoint(double t)
          Uses Hermite interpolation to calculate a point on the curve between the start and end points given the constructor.
 Vec3d calculateReverseTangent(double t)
          Gets the tangent from the calculateTangent() method and reverses its direction.
 Vec3d calculateTangent(double t)
          Uses Hermite interpolation to calculate the tangent of a point on the cubic equation between the start and end points given the constructor.
 Vec3d calculateTranslation(double t)
          If the xyz-point obtained by calculatePoint() is going to be used to translate an object from the origin to the point, then it is convenient for a vector to be returned instead of a point.
 Hermite clone()
          Creates a clone of the calling Hermite object and returns it.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hermite

public Hermite(Point3d p1,
               Point3d p2,
               Vec3d tan1,
               Vec3d tan2)
Constructs a Hermite object by using the input points and vectors to calculate and store the coefficients needed for the cubic equations for x(t), y(t), and z(t).

The input points and vectors are not modified in any way and references to them are not kept.

Parameters:
p1 - the start point of the cubic equation.
p2 - the end point of the cubic equation.
tan1 - the tangent vector for the start point.
tan2 - the tangent vector for the end point.

Hermite

public Hermite(Vec3d p1,
               Vec3d p2,
               Vec3d tan1,
               Vec3d tan2)
Constructs a Hermite object by using the input vectors to calculate and store the coefficients needed for the cubic equations for x(t), y(t), and z(t).

It may be convenient for some calculations to use Vec3d objects rather than Point3d objects to represent the start and end points for the cubic equations.

The input vectors are not modified in any way and references to them are not kept.

Parameters:
p1 - the start point of the cubic equation (as a vector).
p2 - the end point of the cubic equation (as a vector).
tan1 - the tangent vector for the start point.
tan2 - the tangent vector for the end point.
Method Detail

calculatePoint

public Point3d calculatePoint(double t)
Uses Hermite interpolation to calculate a point on the curve between the start and end points given the constructor.

The parameter t must be between 0.0 to 1.0 for interpolation. If t is less than zero or greater than 1, then the result is an extrapolation.

Parameters:
t - a parameter from 0.0 to 1.0.
Returns:
An interpolated point.

calculateTranslation

public Vec3d calculateTranslation(double t)
If the xyz-point obtained by calculatePoint() is going to be used to translate an object from the origin to the point, then it is convenient for a vector to be returned instead of a point.

The vector can be thought of as having its tail at the origin, (0, 0, 0), and its tip at a point on the curved line defined by this Hermite object.

The parameter t must be between 0.0 to 1.0. If it is outside of that range, a vector with all zeros is returned.

Parameters:
t - a parameter from 0.0 to 1.0.
Returns:
A vector from the origin to a point on the spline.

calculateTangent

public Vec3d calculateTangent(double t)
Uses Hermite interpolation to calculate the tangent of a point on the cubic equation between the start and end points given the constructor. The first derivative of the cubic equation is used to calculate the tangent, and the tangent vector is normalized before it is returned.

The parameter t must be between 0.0 to 1.0 for interpolation. If t is less than zero or greater than 1, then the result is an extrapolation.

Parameters:
t - a parameter from 0.0 to 1.0.
Returns:
The tangent vector of an interpolated point.

calculateReverseTangent

public Vec3d calculateReverseTangent(double t)
Gets the tangent from the calculateTangent() method and reverses its direction.

The parameter t must be between 0.0 to 1.0 for interpolation. If t is less than zero or greater than 1, then the result is an extrapolation.

Parameters:
t - a parameter from 0.0 to 1.0.
Returns:
The reverse of the tangent vector at an interpolated point.

clone

public Hermite clone()
Creates a clone of the calling Hermite object and returns it.

The clone is a deep clone (in the sense of being completely independent of the original).

Overrides:
clone in class Object
Returns:
A clone of the calling Hermite object.


Copyright © 2007-2008