bezier_curvemath( int x1, int y1, int hx1, int hy1,
int x2, int y2, int hx2, int hy2, int samples, bool tableGroup )
Generates a table containing the (x, y) of points
of a bezier line between (x1, y1) and (x2, y2).
tableGroup controls table style
false: Ungrouped values: { x1, y1, x2, y2, x3, y3 }
true: Grouped by point: { { xy, y1 }, { x2, y2 }, { x3, y3 } }
]]
function bezier_curvemath( x1, y1, hx1, hy1, x2, y2, hx2, hy2, samples, tableGroup )
local samples = samples or 50
local s = 1/samples
local Ax = x1 + hx1
local Ay = y1 + hy1
local Bx = x2 + hx2
local By = y2 + hy2
local n,xn,yn
local myLocations = { }
for t=0,1,s do
n = 1-t
xn = ( x1 * n^3 ) + t * ( ( 3 * n^2 * Ax ) + t * ( ( 3 * n * Bx ) + ( x2 * t ) ) )
yn = ( y1 * n^3 ) + t * ( ( 3 * n^2 * Ay ) + t * ( ( 3 * n * By ) + ( y2 * t ) ) )
if tableGroup then
table.insert( myLocations, { xn, yn } )
else
table.insert( myLocations, xn )
table.insert( myLocations, yn )
end
end
return myLocations
end

