bezier
An array of three or four vectors, the start point, the endpoint, the first control point and optionally a second control point if the bezier is cubic.
The following functions are in the bezier
module.
quadratic-point
quadratic-point() -> vector
Get the point on quadratic bezier at position t
.
quadratic-derivative
quadratic-derivative() -> vector
Get the derivative (dx/dt) of a quadratic bezier at position t
.
cubic-point
cubic-point() -> vector
Get the point on a cubic bezier curve at position t
.
cubic-derivative
cubic-derivative() -> vector
Get the derivative (dx/dt) of a cubic bezier at position t
.
to-abc
to-abc() -> array
Get a bezier curve's ABC coordinates. Returns them as a respective array of vectors.
/A\ <-- Control point of quadratic bezier
/ | \
/ | \
/_.-B-._\ <-- Point on curve
,' | ',
/ | \
s------C------e <-- Point on line between s and e
quadratic-through-3points
quadratic-through-3points() -> bezier
Compute the control points for a quadratic bezier through 3 points.
cubic-through-3points
cubic-through-3points() -> bezier
Compute the control points for a cubic bezier through 3 points.
quadratic-to-cubic
quadratic-to-cubic() -> bezier
Convert a quadratic bezier to a cubic bezier.
split
split() -> array
Split a cubic bezier into two cubic beziers at the point t
. Returns an array of two bezier. The first holds the original curve start s
, and the second holds the original curve end e
.
cubic-arclen
cubic-arclen() -> float
Get the approximate cubic curve length
cubic-shorten-linear
cubic-shorten-linear() -> bezier
Shorten the curve by offsetting s and c1 or e and c2 by distance d. If d is positive the curve gets shortened by moving s and c1 closer to e, if d is negative, e and c2 get moved closer to s.
cubic-t-for-distance
cubic-t-for-distance() -> float
Approximate bezier interval t
for a given distance d
. If d
is positive, the functions starts from the curve's start s
, if d
is negative, it starts form the curve's end e
.
cubic-shorten
cubic-shorten() -> bezier
Shorten curve by distance d
. This keeps the curvature of the curve by finding new values along the original curve. If d
is positive the curve gets shortened by moving s
closer to e
, if d
is negative, e
is moved closer to s
. The points s
and e
are moved along the curve, keeping the curve's curvature the same (the control points get recalculated).
cubic-extrema
cubic-extrema() -> array
Find cubic curve extrema by calculating the roots of the curve's first derivative. Returns an array of vector ordered by distance along the curve from the start to its end.
cubic-aabb
cubic-aabb() -> array
Returns axis aligned bounding box coordinates (bottom-left, top-right)
for a cubic bezier curve.
catmull-to-cubic
catmull-to-cubic() -> array
Returns an array of cubic bezier for a catmull curve through an array of points.
line-cubic-intersections
line-cubic-intersections() -> array
Calculate the intersection points between a 2D cubic-bezier and a straight line. Returns an array of vector