====================================================================
Bezier Curve examples
====================================================================

A linear Bezier curve is a simple interpolation between the 
starting point and the ending point based on a parameter t.

Given a start point a=[x1,y1] and an endpoint b=[x2,y2]
f(t) == [(1-t)*x1 + t*x2, (1-t)*y1 + t*y2]

n:=linearBezier([2.0,2.0],[4.0,4.0])
   theMap(BEZIER;linearBezier;2LM;1!0,707)

[n(t/10.0) for t in 0..10 by 1]
   [[2.0,2.0], [2.2,2.2], [2.4,2.4], [2.6,2.6], [2.8,2.8], [3.0,3.0],
    [3.2,3.2], [3.4,3.4], [3.6,3.6], [3.8,3.8], [4.0,4.0]]


A quadratic Bezier curve is a simple interpolation between the 
starting point, a middle point, and the ending point based on 
a parameter t.

Given a start point a=[x1,y1], a middle point b=[x2,y2], 
and an endpoint c=[x3,y3]

f(t) == [(1-t)^2 x1 + 2t(1-t) x2 + t^2 x3,
         (1-t)^2 y1 + 2t(1-t) y2 + t^2 y3]

n:=quadraticBezier([2.0,2.0],[4.0,4.0],[6.0,2.0])
   theMap(BEZIER;quadraticBezier;3LM;2!0,291)

[n(t/10.0) for t in 0..10 by 1]
   [[2.0,2.0], [2.4,2.36], [2.8,2.64], [3.2,2.84], [3.6,2.96], [4.0,3.0],
    [4.4,2.96], [4.8,2.84], [5.2,2.64], [5.6,2.36], [6.0,2.0]]

A cubic Bezier curve is a simple interpolation between the 
starting point, a left-middle point,, a right-middle point,
and the ending point based on a parameter t.

Given a start point a=[x1,y1], the left-middle point b=[x2,y2],
the right-middle point c=[x3,y3] and an endpoint d=[x4,y4]

f(t) == [(1-t)^3 x1 + 3t(1-t)^2 x2 + 3t^2 (1-t) x3 + t^3 x4,
         (1-t)^3 y1 + 3t(1-t)^2 y2 + 3t^2 (1-t) y3 + t^3 y4]

n:=cubicBezier([2.0,2.0],[2.0,4.0],[6.0,4.0],[6.0,2.0])
   theMap(BEZIER;cubicBezier;4LM;3!0,915)

[n(t/10.0) for t in 0..10 by 1]
   [[2.0,2.0], [2.112,2.54], [2.416,2.96], [2.864,3.26], [3.408,3.44],
    [4.0,3.5], [4.592,3.44], [5.136,3.26], [5.584,2.96], [5.888,2.54],
    [6.0,2.0]]

Bezier curves "move" based on moving their control points, which
in the case of the three components of a quadratic Bezier curve
are the three points given. To see this motion we can show what
happens when you "drag" the middle control point along the line
from [-4,4] to [4,4] by increments of 1. 

First, we form the line as a list of Floats, 9 in all.

   line:=[[i::Float,4.0] for i in -4..4 by 1]

Next, we form a list of functions, each with a different center control point.
Notice that the endpoints remain fized so we expect that the curve will
begin and end at the same point but that the midpoint is pulled around.

  functions:=[quadraticBezier([2.0,2.0],m,[6.0,2.0]) for m in line]

Then we form a list of the graphs by calling each function in the above
list. Each function call happens 101 times (to include both endpoints).
Thus we get a List of Lists of Points of DoubleFloats

  graphs:=[ [ point( ( (functions.i)(j/100.0) )::LIST(DFLOAT) ) _
    for j in 0..100] for i in 1..9]

We draw the first graph to see if it looks reasonable:

  d1:=draw(graphs.1)

Since it does we add the other 8 graphs. The 2D graphs can hold up to
9 simultaneous graphs.

  others:=[graphs.i for i in 2..9]
  for i in 2..9 for graph in others repeat putGraph(d1,[graph],i)

and now we display them all on one graph.

  vp:=makeViewport2D(d1)

See Also:
o )show Bezier
o )show TwoDimensionalViewport
o )d op draw
o )d op point
o )d op putGraph
o )d op makeViewport2D

