Skip to main content

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() 

Get the point on quadratic bezier at position t.

Start point

End point

Control point

Position on curve

quadratic-derivative

quadratic-derivative() 

Get the derivative (dx/dt) of a quadratic bezier at position t.

Start point

End point

Control point

Position on curve [0, 1]

cubic-point

cubic-point() 

Get the point on a cubic bezier curve at position t.

Start point

End point

Control point 1

Control point 2

Position on curve [0, 1]

cubic-derivative

cubic-derivative() 

Get the derivative (dx/dt) of a cubic bezier at position t.

Start point

End point

Control point 1

Control point 2

Position on curve [0, 1]

to-abc

to-abc() 

Get a bezier curve’s ABC coordinates. Returns them as a respective array</Type> of vector</Type>s.

       /A\  <-- Control point of quadratic bezier
/ | <br /> / | <br /> /.-B-.\ <-- Point on curve
,' | ',
/ | <br /> s------C------e <-- Point on line between s and e

Curve start

Curve end

Point on curve

Position on curve

deg:

Bezier degree (2 or 3)

quadratic-through-3points

quadratic-through-3points() 

Compute the control points for a quadratic bezier through 3 points.

Curve start

Curve end

A point which the curve passes through

quadratic-to-cubic

quadratic-to-cubic() 

Convert a quadratic bezier to a cubic bezier.

Curve start

Curve end

Control point

cubic-through-3points

cubic-through-3points() 

Compute the control points for a cubic bezier through 3 points.

Curve start

Curve end

A point which the curve passes through

split

split() 

Split a cubic bezier into two cubic beziers at the point t. Returns an array</Type> of two bezier</Type>. The first holds the original curve start s, and the second holds the original curve end e.

Curve start

Curve end

Control point 1

Control point 2

The point on the bezier to split,

cubic-arclen

cubic-arclen() 

Get the approximate cubic curve length

Curve start

Curve end

Control point 1

Control point 2

cubic-shorten-linear

cubic-shorten-linear() 

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.

Curve start

Curve end

Control point 1

Control point 2

Distance to shorten by

cubic-t-for-distance

cubic-t-for-distance() 

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.

Curve start

Curve end

Control point 1

Control point 2

The distance along the bezier to find t.

cubic-shorten

cubic-shorten() 

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).

Curve start

Curve end

Control point 1

Control point 2

Distance to shorten by

samples:

Maximum of samples/steps to use

cubic-extrema

cubic-extrema() 

Find cubic curve extrema by calculating the roots of the curve’s first derivative. Returns an array</Type> of vector</Type> ordered by distance along the curve from the start to its end.

Curve start

Curve end

Control point 1

Control point 2

cubic-aabb

cubic-aabb() 

Returns axis aligned bounding box coordinates (bottom-left, top-right) for a cubic bezier curve.

Curve start

Curve end

Control point 1

Control point 2

catmull-to-cubic

catmull-to-cubic() 

Returns an array of cubic bezier</Type> for a catmull curve through an array of points.

points:

Array of 2d points

Strength between 0 and 1

close:

line-cubic-intersections

line-cubic-intersections() 

Calculate the intersection points between a 2D cubic-bezier and a straight line. Returns an array of vector</Type>

Bezier start point

Bezier end point

Bezier control point 1

Bezier control point 2

Line start point

Line end point

ray:

If set to true, ignore line length