Index | OAT homepage | OpenLink Software

bezier.js

bezier.js

Provides two mathematical functions for drawing Bezier curves.

Functions

OAT.Bezier.setPointList(pointList)

Marks an array of 2D points as a base for a Bezier curve.

OAT.Bezier.initFactorial(max)

Pre-computes factorials of 1..max for later execution. Call this function once, in the initialization part of your script. This speeds up creation of bezier curves using OAT.Bezier.create2() function. Set the max argument to the number of points.

OAT.Bezier.create()

Returns a Bezier functionf: [0,1] -> R^2 which describes parametric Bezier curve, based on points set by OAT.Bezier.setPointList().

Uses slow but precise recursive de Casteljau's algorithm .

OAT.Bezier.create2()

Returns a Bezier functionf: [0,1] -> R^2 which describes parametric Bezier curve, based on points set by OAT.Bezier.setPointList().

Uses faster factorial algorithm based directly on Bernstein polynomials.

Example


var points = [];
points.push([0,0]);
points.push([1,0]);
points.push([1,1]);
OAT.Bezier.setPointList(points);
var f = OAT.Bezier.create2();
alert(f(0.5)); // [x, y] where x in [0,1], y in [0,1]
Copyright (C) 2005-2009 OpenLink Software