Bezier curves

Your browser does not support the canvas element.


Instructions
+ click on an empty zone to spawn a point
+ click on a segment to split it in two
+ move points by dragging them
+ move points out of the canvas to delete them


De Casteljeau's algorithm
The demo uses De Casteljeau's algorithm to draw the curves
Here's the algorithm in pseudocode:

P is the array where the control points are stored
Pt is an auxilliary array used by the algorithm

For u := 0 to 1, step 0.01
 Copy the contents of P in Pt
 For i := 0 to #_points
  Decrement #_points_tmp by 1
  For j := 0 to #_points_tmp
   Pt[i] := Pt[i] + u * (Pt[i+1] - Pt[i]);
 Plot Pt[0]

0 comments:

Post a Comment