@baku89/pave / Arc
Arc
A collection of functions to handle arcs represented with SegmentA.
Utilities
toCenterParameterization()
toCenterParameterization(
arg):object
Defined in: Arc.ts:55
Converts the Arc command to a center parameterization that can be used in Context2D.ellipse(). https://observablehq.com/@awhitty/svg-2-elliptical-arc-to-canvas-path2d
Parameters
| Parameter | Type |
|---|---|
arg | BareSegmentA |
Returns
object
| Name | Type | Default value |
|---|---|---|
angles | AngleRange | - |
center | vec2 | - |
radii | vec2 | - |
sweep | boolean | true |
xAxisRotation | number | - |
Other
approximateByCubicBeziers()
approximateByCubicBeziers(
arc,tolerance):VertexC[]
Defined in: Arc.ts:151
Approximates the arc by cubic Béziers so that the deviation from the true arc stays within tolerance. The sweep is split into equal steps of at most 90°, whose size is solved from the sixth-power error law of the cubic arc approximation. For elliptic arcs the larger radius is used, which is conservative.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
arc | BareSegmentA | undefined | The arc to approximate |
tolerance | number | 0.05 | The maximum deviation allowed, in the same unit as the coordinates |
Returns
VertexC[]
The vertices of the approximating cubics, excluding the start point
bounds()
bounds(
arg):Rect
Defined in: Arc.ts:239
Calculates the bound of given arc.
Parameters
| Parameter | Type | Description |
|---|---|---|
arg | BareSegmentA | The arc segment to calculate |
Returns
Rect
The bound of the arc
Example
curvature()
curvature(
arc,loc):number
Defined in: Arc.ts:624
Returns the signed curvature at the given location. Positive when the arc turns towards its normal side.
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
number
derivative()
derivative(
arc,loc):vec2
Defined in: Arc.ts:403
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
vec2
divideAtTimes()
divideAtTimes(
arc,times):VertexA[]
Defined in: Arc.ts:457
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
times | Iterable<number> |
Returns
VertexA[]
ellipticArcLength()
ellipticArcLength(
radii,angles):number
Defined in: Arc.ts:534
Computes the arc length of an ellipse over a range of centric angles.
The integrand |d/dt (rx cos t, ry sin t)| is smooth but has sharp dips near the minor axis of an eccentric ellipse, so a single fixed-order quadrature over a wide span loses accuracy. The span is therefore cut at quadrant boundaries and Gauss–Legendre quadrature is applied to each piece (see ellipticArcLengthRad for the accuracy this achieves).
Parameters
| Parameter | Type |
|---|---|
radii | vec2 |
angles | AngleRange |
Returns
number
isCircular()
isCircular(
arc):boolean
Defined in: Arc.ts:555
Returns true if the arc lies on a circle (equal radii).
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
Returns
boolean
isStraight()
isStraight(
arc,tolerance):boolean
Defined in: Arc.ts:496
Parameters
| Parameter | Type | Default value |
|---|---|---|
arc | BareSegmentA | undefined |
tolerance | number | 0 |
Returns
boolean
isZero()
isZero(
arg):boolean
Defined in: Arc.ts:491
Returns true if the length of arc segment is zero.
Parameters
| Parameter | Type |
|---|---|
arg | BareSegmentA |
Returns
boolean
length()
length(
arg):number
Defined in: Arc.ts:370
Parameters
| Parameter | Type |
|---|---|
arg | BareSegmentA |
Returns
number
normal()
normal(
arc,loc):vec2
Defined in: Arc.ts:422
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
vec2
of()
of(
start,radii,xAxisRotation,largeArcFlag,sweepFlag,point):SegmentA
Defined in: Arc.ts:34
Parameters
| Parameter | Type |
|---|---|
start | vec2 |
radii | vec2 |
xAxisRotation | number |
largeArcFlag | boolean |
sweepFlag | boolean |
point | vec2 |
Returns
offset()
offset(
arc,distance,tolerance):Path
Defined in: Arc.ts:652
Returns the raw parallel curve of the arc at the given signed distance along its normal, as an open path. Circular arcs stay circular arcs (A); elliptic arcs are approximated by cubic Béziers within tolerance.
Parameters
| Parameter | Type | Default value |
|---|---|---|
arc | BareSegmentA | undefined |
distance | number | undefined |
tolerance | number | 0.05 |
Returns
point()
point(
arc,loc):vec2
Defined in: Arc.ts:394
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
vec2
tangent()
tangent(
arc,loc):vec2
Defined in: Arc.ts:418
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
vec2
tangentTimes()
tangentTimes(
arc,direction):number[]
Defined in: Arc.ts:579
Sorted t values in (0, 1) where the tangent of the arc is parallel to direction.
Parameters
| Parameter | Type | Description |
|---|---|---|
arc | BareSegmentA | - |
direction | vec2 | The direction to compare the tangent with. Its length does not matter. |
Returns
number[]
tangentTimesFrom()
tangentTimesFrom(
arc,origin):number[]
Defined in: Arc.ts:599
Sorted t values in (0, 1) where the line from origin to the arc is tangent to it. There are none when origin lies inside the ellipse.
Parameters
| Parameter | Type | Description |
|---|---|---|
arc | BareSegmentA | - |
origin | vec2 | The point the tangents pass through |
Returns
number[]
toTime()
toTime(
arc,loc):number
Defined in: Arc.ts:375
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
loc | SegmentLocation |
Returns
number
transform()
transform(
arc,matrix):SegmentA
Defined in: Arc.ts:284
Transforms the given arc segment with the given matrix.
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
matrix | mat2d |
Returns
See
https://gist.github.com/timo22345/9413158#file-flatten-js-L443-L547
trim()
trim(
arc,start,end):SegmentA
Defined in: Arc.ts:426
Parameters
| Parameter | Type |
|---|---|
arc | BareSegmentA |
start | SegmentLocation |
end | SegmentLocation |