AS 3 Parametric Curve Library

This library illustrates many practical Actionscript 3 concepts via the development of a 2D parametric curve library. The current library consists of a base set of Classes for constructing single-segment and composite (piecewise) parametric curves. For more information and regular updates, visit Jim Armstrong's personal blog.

Flex MXML files are provided to illustrate the application of the library. Check back often as I expect new Classes to be added.

Current Release (9/08): 1.0 - Baseline functionality is frozen - added cubic Bezier 4-point interpolation.

 
Singularity Package Contents (parametric curve library)

All classes in the parametric curve library are in the Singularity package, which must be added to your path when building a new Flex project. The current package organization is as follows,

Singularity.Events
  Dispatcher - Illustrates how to apply an event dispatcher via Composition
  SingularityEvent - Common event management for all Classes in Singularity package

Singularity.Geom
  Bezier - K-th order Bezier curve
  Bezier2 - Base quadratic Bezier (includes 3-point, auto-parametrized interpolation)
  Bezier3 - Base cubic Bezier with recursive midpoint subdivision for drawing
  BezierFactory - Returns appropriate Bezier instance based on number of control points
  BezierSpline - Piecewise cubic bezier that interpolates a set of knots
  BezierSplineControl - Tangent construction control-point generation for bezier spline
  CatmullRom - Catmull-Rom spline with uniform or arc-length parameterization
  Composite - Base, pseudo-abstract class for composite or piecewise parametric curves
  Coef - Manages creation, evaluation, and differentiation of a arbitrary-order polynomial
  Cubic - Manages creation, evaluation, and differentiation of a cubic polynomial
  CubicCage - Control cage for a single cubic segment in a piecewise Bezier curve
  Ellipse - Arc-length parametrized Ellipse (useful for distributing sprites evenly around an ellipse
  FastCubicSpline - Natural cubic spline without error checking and does not subclass Composite
  FastBezier - Cubic bezier with customized subdivision trading quality for faster drawing
  IParametric - Interface for all single-segment parametric curves
  IPoly - Interface for polynomials of arbitrary degree
  Knot - Visual representation of a point
  Quad - Manages creation, evaluation, and differentiation of a quadratic polynomial
  Spline3 - Natural cubic spline (non-overlapping intervals)
  PSpline3 - Parametric cubic spline (abitrary knots)
  Wedge - Draw pie-shaped wedges using quad. bezier for circular arcs

Singularity.Geom.P3D   The following methods have been ported for use in 3D applications such as Papervision 3D. Online demos for these methods and those from the 2D Parameteric curve library, along with supporting TechNotes, may be found here.

  BezierSpline
  CatmullRom
  Composite
  Cubic
  CubicCage
  FastCubicSpline
  FastBezier
  IPoly
  Knot
  PV3DSpline - Spline designed to work with knot data exported from a package such as 3ds max

Singularity.Interactive
  PointSelector - Enable point selection by mouse over a colored background 'drawing area'
  RectangleSelector - Click and drag to define a rectangular selection inside 'drawing area'

Singularity.Numeric
  Binomial - Generates Binomial coefficients (forward- and backward-recursion of Pascal's triangle)
  Bisect - Recursive bisection method to isolate root in an interval
  Consts - Absolute and machine-dependent constants
  Gauss - Gauss-Legendre Integration
  Newton - AS3 Implementation of Newton's method
  Halley - AS3 Implementation of Halley's method
  SimpleRoot - AS3 Implementation of Jack Crenshaw's TWBRF
  Solve2x2 - Solves 2x2 systems of equations using Cramer's rule

Singularity.Utils
  BezierUtils - Bezier utilities class (currently contains methods for general Bezier subdivision and closest point algorithm)

 
Flex test programs

Test programs consist of MXML files from which you may create a new project (make sure the Singularity package is in your build path). All MXML files are contained in the Singularity\demos folder.

  BezierClosedSpline - Test driver for cubic Bezier spline with arc-length parameterization and closed-loop support (auto-closure)
  BezierEasing - Penner easing functions applied to easing along a parametric curve with arc-length parametrization
  BezierNumeric - Demo [in progress] to illustrate k-th order Bezier curves and compare naive formula vs. coefficient generation and numerical issues. Long-term goal is to illustrate general application of deCasteljau's method.
  BezierSplineTest - Test driver for cubic Bezier spline
  BezierParameterization - Illustrate difference between uniform and arc-length parameterization for a cubic bezier spline
  BezierTest - Test driver for quadratic and cubic Bezier curves and BZFactory class
  CatmullRomTest - Test driver for Catmull-Rom splline
  ClosestToCubic - Closest point on a cubic Bezier to an arbitrary point
  ClosestToQuad - Closest point on a quadratic Bezier to an arbitrary point
  CRAnimation - Illustrate drawing C-R spline from beginning to end
  CRClosedSpline - Illustrate closed-loop Catmull-Rom Spline
  CRClosed2 - Closed-loop Catmull-Rom Spline used to approximate a figure-8 or infinity shape
  CubicBezierInterpolation - Cubic Bezier, 4-point interpolation
  EllipseTest - Test driver illustrating ellipse creation and parametrizations (polar and arc-length)
  PSplineTest - Test driver for cubic parametric spline
  SplineTest - Test driver for natural cubic spline
  PathTween - Illustrates constant-velocity sprite animation along a Catmull-Rom spline
  PathTween2 - Illustrates direct scripting of embedded image instead of mx:Image control
  QuadInterpolation - Illustrates effect of parameterization on 3-point quad. Bezier interpolation
  QuadBezierParam - Illustrates natural vs. arc-length parameterization of a quadratic Beizer curve
  WedgeTest - Interactive drawing and modification of pie-shaped wedge

 
Papervision 3D Examples

Refer to the TechNotes page for a list of online demos including the use of Singularity in PV3D.

 
Download

The Singularity AS 3 parametric curve library requires the Flash 9 player and a development environment supporting Actionscript 3. All demonstration programs were created with FlexBuilder 2. The AS 3 parametric curve library is copyrighted and licensed for personal, experimental usage. Please contact me to obtain authorization for commercial use. My primary interest is to ensure that the library is not commericalized and resold as a standalone library or packaged as a standalone component.

The download includes the entire Singularity package (which includes the rigging classes).

Download library (.zip) here. Before running any example programs, place the Singularity package in your build path.