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

Get the point on quadratic bezier at position t.

Start point

End point

Control point

Position on curve [0,1][0, 1]

quadratic-derivative

quadratic-derivative() -> vector 

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

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

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

Curve start

Curve end

Point on curve

Position on curve [0,1][0, 1]

deg:

Default: 2

Bezier degree (2 or 3)

quadratic-through-3points

quadratic-through-3points() -> bezier 

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

Curve start

Curve end

A point which the curve passes through

cubic-through-3points

cubic-through-3points() -> bezier 

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

Curve start

Curve end

A point which the curve passes through

quadratic-to-cubic

quadratic-to-cubic() -> bezier 

Convert a quadratic bezier to a cubic bezier.

Curve start

Curve end

Control point

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.

Curve start

Curve end

Control point 1

Control point 2

The point on the bezier to split, [0,1][0, 1]

cubic-arclen

cubic-arclen() -> float 

Get the approximate cubic curve length

Curve start

Curve end

Control point 1

Control point 2

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.

Curve start

Curve end

Control point 1

Control point 2

Distance to shorten by

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.

Curve start

Curve end

Control point 1

Control point 2

The distance along the bezier to find t.

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

Curve start

Curve end

Control point 1

Control point 2

Distance to shorten by

samples:

Default: 15

Maximum of samples/steps to use

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.

Curve start

Curve end

Control point 1

Control point 2

cubic-aabb

cubic-aabb() -> array 

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

Returns an array of cubic bezier for a catmull curve through an array of points.

points:

Array of 2d points

Strength between 0 and 1

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

Bezier start point

Bezier end point

Bezier control point 1

Bezier control point 2

Line start point

Line end point

ray:

Default: false

If set to true, ignore line length