Curve

Curve class provides static functions to interpolate curves. A curve is usually represented as a Group of 3 or more control points. You can use the static functions as-is, or apply the Group.op or Pt.op to enable functional programming. See Op guide for details.

Class in src/Op.ts

Methods

STATIC bezier ( pts, steps )

Create a Bezier curve. In a cubic bezier curve, the first and 4th anchors are end-points, and 2nd and 3rd anchors are control-points.

parameters
pts: GroupLike

a group of anchor Pt

steps: number (default value: 10)

the number of line segments per curve. Defaults to 10 steps.

returns
Group

a curve as a group of interpolated Pt

source

STATIC bezierStep ( step, ctrls )

Interpolate to get a point on a cubic Bezier curve.

parameters
step: Pt

the coefficients [tt*t, tt, t, 1]

ctrls: GroupLike

a group of anchor Pts

returns
Pt

an interpolated Pt on the curve

source

STATIC bspline ( pts, steps, tension )

Create a basis spline (NURBS) curve.

parameters
pts: GroupLike

a group of anchor Pt

steps: number (default value: 10)

the number of line segments per curve. Defaults to 10 steps.

tension: number (default value: 1)

optional value between 0 to n to specify a "tension". Default is 1 which is the usual tension.

returns
Group

a curve as a group of interpolated Pt

source

STATIC bsplineStep ( step, ctrls )

Interpolate to get a point on a basis spline curve.

parameters
step: Pt

the coefficients [tt*t, tt, t, 1]

ctrls: GroupLike

a group of anchor Pts

returns
Pt

an interpolated Pt on the curve

source

STATIC bsplineTensionStep ( step, ctrls, tension )

Interpolate to get a point on a basis spline curve with tension.

parameters
step: Pt

the coefficients [tt*t, tt, t, 1]

ctrls: GroupLike

a group of anchor Pts

tension: number (default value: 1)

optional value between 0 to n to specify a "tension". Default to 1 which is the usual tension.

returns
Pt

an interpolated Pt on the curve

source

STATIC cardinal ( pts, steps, tension )

Create a Cardinal curve.

parameters
pts: PtLikeIterable

a Group or an Iterable

steps: number (default value: 10)

the number of line segments per curve. Defaults to 10 steps.

tension: number (default value: 0.5)

optional value between 0 to 1 to specify a "tension". Default to 0.5 which is the tension for Catmull-Rom curve.

returns
Group

a curve as a group of interpolated Pt

source

STATIC cardinalStep ( step, ctrls, tension )

Interpolate to get a point on Cardinal curve.

parameters
step: Pt

the coefficients [tt*t, tt, t, 1]

ctrls: GroupLike

a group of anchor Pts

tension: number (default value: 0.5)

optional value between 0 to 1 to specify a "tension". Default to 0.5 which is the tension for Catmull-Rom curve

returns
Pt

an interpolated Pt on the curve

source

STATIC catmullRom ( pts, steps )

Create a Catmull-Rom curve. Catmull-Rom is a kind of smooth-looking Cardinal curve.

parameters
pts: PtLikeIterable

a Group or an Iterable

steps: number (default value: 10)

the number of line segments per curve. Defaults to 10 steps

returns
Group

a curve as a group of interpolated Pt

source

STATIC catmullRomStep ( step, ctrls )

Interpolate to get a point on Catmull-Rom curve.

parameters
step: Pt

the coefficients [tt*t, tt, t, 1]

ctrls: GroupLike

a group of anchor Pts

returns
Pt

an interpolated Pt on the curve

source

STATIC controlPoints ( pts, index, copyStart )

Given an index for the starting position in a Pt group, get the control and/or end points of a curve segment.

parameters
pts: PtLikeIterable

a Group or an Iterable

index: number (default value: 0)

start index in pts array. Default is 0.

copyStart: boolean (default value: false)

an optional boolean value to indicate if the start index should be used twice. Default is false.

returns
Group

a group of 4 Pts

source

STATIC getSteps ( steps )

Get a precalculated coefficients per step.

parameters
steps: number

number of steps

returns
Group

source