PavePave
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
  • CubicBezier

@baku89/pave v1.0.1


@baku89/pave / CubicBezier

CubicBezier

A collection of functions to handle a cubic Bézier segment represented as BareSegmentC.

The projection strategy follows bezier-js (MIT, https://github.com/Pomax/bezierjs).

Functions

bounds()

bounds(arg): [vec2, vec2]

Defined in: CubicBezier.ts:46

Calculates the rect of this Bezier curve.

Parameters

ParameterType
argBareSegmentC

Returns

[vec2, vec2]


curvature()

curvature(bezier, loc): number

Defined in: CubicBezier.ts:121

Signed curvature κ = (B′ × B″) / ‖B′‖³ at the specified location. Positive when the curve turns towards its normal side. Returns 0 where the speed vanishes.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

number


cuspTimes()

cuspTimes(bezier): number[]

Defined in: CubicBezier.ts:198

The t values in (0, 1) where the speed vanishes, so that the curve turns back on itself. A cubic has at most one unless it is degenerate to a line.

Parameters

ParameterType
bezierBareSegmentC

Returns

number[]


derivative()

derivative(bezier, loc): vec2

Defined in: CubicBezier.ts:88

Calculates the curve tangent at the specified t value. Note that this yields a not-normalized vector.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

vec2


divideAtTimes()

divideAtTimes(segment, times): VertexC[]

Defined in: CubicBezier.ts:370

Parameters

ParameterType
segmentBareSegmentC
timesIterable<number>

Returns

VertexC[]


extremaTimes()

extremaTimes(bezier): number[]

Defined in: CubicBezier.ts:135

Sorted, unique t values in (0, 1) where x(t) or y(t) has an extremum. Splitting at these times yields pieces that are monotone along both axes.

Parameters

ParameterType
bezierBareSegmentC

Returns

number[]


fromQuadraticBezier()

fromQuadraticBezier(start, control, point): SegmentC

Defined in: CubicBezier.ts:25

Parameters

ParameterType
startvec2
controlvec2
pointvec2

Returns

SegmentC


inflectionTimes()

inflectionTimes(bezier): number[]

Defined in: CubicBezier.ts:148

Sorted t values in (0, 1) where the curvature changes sign (B′ × B″ = 0).

Parameters

ParameterType
bezierBareSegmentC

Returns

number[]


isStraight()

isStraight(bezier, tolerance): boolean

Defined in: CubicBezier.ts:400

Parameters

ParameterTypeDefault value
bezierBareSegmentCundefined
tolerancenumber0

Returns

boolean


isZero()

isZero(bezier): boolean

Defined in: CubicBezier.ts:387

Parameters

ParameterType
bezierBareSegmentC

Returns

boolean


length()

length(bezier): number

Defined in: CubicBezier.ts:39

Calculates the length of the Bezier curve. Length is calculated using numerical approximation, specifically the Legendre-Gauss quadrature algorithm.

Parameters

ParameterType
bezierBareSegmentC

Returns

number


normal()

normal(bezier, loc): vec2

Defined in: CubicBezier.ts:114

Calculates the curve normal at the specified t value. Note that this yields a normalized vector.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

vec2


of()

of(start, control1, control2, point): SegmentC

Defined in: CubicBezier.ts:16

Parameters

ParameterType
startvec2
control1vec2
control2vec2
pointvec2

Returns

SegmentC


offset()

offset(bezier, distance, tolerance): Path

Defined in: CubicBezier.ts:483

Returns the raw parallel curve of the Bézier at the given signed distance along its normal, as an open path of cubic Béziers fitted within tolerance. Where the distance exceeds the radius of curvature the result folds back on itself; use Path.offset for a trimmed result.

Parameters

ParameterTypeDefault value
bezierBareSegmentCundefined
distancenumberundefined
tolerancenumber0.05

Returns

Path


point()

point(bezier, loc): vec2

Defined in: CubicBezier.ts:80

Calculates the point on the curve at the specified t value.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

vec2


project()

project(bezier, origin): object

Defined in: CubicBezier.ts:290

Finds the on-curve point closest to the specific off-curve point

Parameters

ParameterType
bezierBareSegmentC
originvec2

Returns

object

NameType
distance?number
positionvec2
t?number

secondDerivative()

secondDerivative(bezier, loc): vec2

Defined in: CubicBezier.ts:96

Calculates the second derivative d²B/dt² at the specified t value.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

vec2


selfIntersectionTimes()

selfIntersectionTimes(bezier): null | [number, number]

Defined in: CubicBezier.ts:171

The two t values at which the curve passes through the same point, or null if it has no loop. Solved in closed form: with B(t) = at³ + bt² + ct + d, dividing B(s) - B(t) by s - t leaves an equation in s + t and st.

Parameters

ParameterType
bezierBareSegmentC

Returns

null | [number, number]


tangent()

tangent(bezier, loc): vec2

Defined in: CubicBezier.ts:107

Calculates the curve tangent at the specified t value. Unlike derivative, this yields a normalized vector.

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

vec2


tangentTimes()

tangentTimes(bezier, direction): number[]

Defined in: CubicBezier.ts:220

Sorted t values in (0, 1) where the tangent is parallel to direction. These are the points where a line along direction touches the curve, and where the curve is farthest along the perpendicular of direction.

Parameters

ParameterTypeDescription
bezierBareSegmentC-
directionvec2The direction to compare the tangent with. Its length does not matter.

Returns

number[]


tangentTimesFrom()

tangentTimesFrom(bezier, origin): number[]

Defined in: CubicBezier.ts:236

Sorted t values in (0, 1) where the line from origin to the curve is tangent to it. The condition (B(t) − origin) × B′(t) = 0 is a quintic, so the roots are found by bracketing sign changes and bisecting.

Parameters

ParameterTypeDescription
bezierBareSegmentC-
originvec2The point the tangents pass through

Returns

number[]


toTime()

toTime(bezier, loc): number

Defined in: CubicBezier.ts:59

Parameters

ParameterType
bezierBareSegmentC
locSegmentLocation

Returns

number


trim()

trim(bezier, start, end): SegmentC

Defined in: CubicBezier.ts:330

Parameters

ParameterType
bezierBareSegmentC
startSegmentLocation
endSegmentLocation

Returns

SegmentC

Edit this page