class Geometry · Computations

Arcs

Computations on circular arcs: creating them (from three points, a pin, a sagitta, a circle), points, pins and directions along them, length, area and sweep angle.

An arc is given by its start, middle and end point, which fix the circle, the extent and the direction.

Static methods

arc3Pstatic

static arc3P(p1: Point | VectorLike, p2: Point | VectorLike, p3: Point | VectorLike, result?: Arc | null): Arc

Creates the arc that starts at p1, passes through p2 and ends at p3 (like Circles.circle3P for circles). E.g. an arc bent by three handles.

The middle point decides which way the arc runs, so there is no direction to choose. Three points on a line have no arc: the result is NaN.

p1
The start of the arc.
p2
A point the arc passes through.
p3
The end of the arc.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns The arc through the three points.

arcAtstatic

static arcAt(center: Point | VectorLike, radius: Real | NumberLike, startAngle: Real | NumberLike, sweepAngle: Real | NumberLike, result?: Arc | null): Arc

Constructs an arc from a center point, radius, start angle, and sweep angle.

center
The center of the underlying circle.
radius
The radius of the arc.
startAngle
The angle at which the arc begins, in radians.
sweepAngle
The angular extent of the arc, in radians. Positive values sweep clockwise on screen; negative values sweep counter-clockwise. The sweep is limited to one full turn (+-2π).
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc starting at startAngle and sweeping by sweepAngle.

arcAtPinstatic

static arcAtPin(pin: Pin | PinLike, sweepAngle: Real | NumberLike, result?: Arc | null): Arc

Creates an arc from a pin: centered at the pin's position, starting at the pin's tip (the pin's length is the radius) and sweeping by sweepAngle. E.g. a clock hand's sweep: Arcs.arcAtPin(hand, Math.PI / 2, arc).

A positive sweep runs clockwise on the screen (y pointing down), as in arcAt; the sweep is limited to one full turn either way. Turned copies of the pin (Pins.rotateBy) give turned arcs without angle math.

pin
The center (position), radius (length) and start direction.
sweepAngle
The angle the arc covers, in radians; positive clockwise.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns The arc.

arcBetweenstatic

static arcBetween(center: Point | VectorLike, radius: Real | NumberLike, startAngle: Real | NumberLike, endAngle: Real | NumberLike, clockwise: Bool | BoolLike, result?: Arc | null): Arc

Constructs an arc from a center point, radius, start angle, and end angle, with explicit winding direction.

center
The center of the underlying circle.
radius
The radius of the arc.
startAngle
The angle at which the arc begins, in radians.
endAngle
The angle at which the arc ends, in radians.
clockwise
If true, the arc travels clockwise from startAngle to endAngle; otherwise counter-clockwise.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc from startAngle to endAngle in the specified winding direction.

arcFromCirclestatic

static arcFromCircle(circle: Circle | ShapeLike, startAngle: Real | NumberLike, sweepAngle: Real | NumberLike, result?: Arc | null): Arc

Constructs an arc on an existing circle between two angles with a given sweep.

circle
The circle on which the arc lies.
startAngle
The angle at which the arc begins, in radians.
sweepAngle
The angular extent of the arc, in radians. Positive values sweep clockwise on screen; negative values sweep counter-clockwise. The sweep is limited to one full turn (+-2π).
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc on circle starting at startAngle and sweeping by sweepAngle.

arcFromPointsstatic

static arcFromPoints(center: Point | VectorLike, start: Point | VectorLike, end: Point | VectorLike, clockwise: Bool | BoolLike, result?: Arc | null): Arc

Creates an arc around a center from a start point to the direction of an end point, e.g. a wedge or an angle marker from a center and two handles: Arcs.arcFromPoints(center, a, b, true, arc).

The radius is the distance from center to start; end only gives the direction where the arc ends (its distance is not used). clockwise picks one of the two arcs, clockwise on the screen (y pointing down) as in arcBetween.

center
The center of the arc.
start
The start of the arc.
end
A point in the direction where the arc ends.
clockwise
true: from start to end clockwise on the screen; false: counterclockwise.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns The arc.

arcFromSagittastatic

static arcFromSagitta(start: Point | VectorLike, end: Point | VectorLike, sagitta: Real | NumberLike, result?: Arc | null): Arc

Constructs an arc from two endpoints and a sagitta (the signed height from the chord midpoint to the arc midpoint). Positive sagitta curves to the left of the start-to-end direction; negative curves to the right.

start
The start point of the arc.
end
The end point of the arc.
sagitta
The signed perpendicular distance from the chord midpoint to the arc midpoint.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc from start to end with the specified curvature. A sagitta of 0 gives a straight arc (infinite radius).

areastatic

static area(arc: Arc | ShapeLike, result?: Real | null): Real

Computes the area of the circular sector defined by the arc.

arc
The arc whose sector area is computed.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The area of the sector swept by arc.

boundingBoxstatic

static boundingBox(arc: Arc | ShapeLike, result?: Box | null): Box

Computes the axis-aligned bounding box of the arc.

arc
The arc whose bounding box is computed.
result optional
Optional Box to write the result into; it is returned. Without it, a new Box is returned.

Returns The smallest axis-aligned box that contains all points on arc.

centerstatic

static center(arc: Arc | ShapeLike, result?: Point | null): Point

Returns the center of the underlying circle of the arc.

arc
The arc to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The center point of the circle on which arc lies.

chordLengthstatic

static chordLength(arc: Arc | ShapeLike, result?: Real | null): Real

Computes the straight-line distance between the start and end points of the arc.

arc
The arc to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The length of the chord from the start point to the end point of arc.

closestPointstatic

static closestPoint(arc: Arc | ShapeLike, p: Point | VectorLike, result?: Point | null): Point

Computes the closest point on the arc to a given point. If the projection of the point falls outside the arc's angular range, the nearest endpoint is returned.

arc
The arc to project onto.
p
The point to project.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The point on arc closest to p.

closestPositionstatic

static closestPosition(arc: Arc | ShapeLike, p: Point | VectorLike, result?: Real | null): Real

Computes the normalized position of the closest point on the arc to a given point. If the projection falls outside the arc's angular range, 0 or 1 is returned for the nearest endpoint.

arc
The arc to project onto.
p
The point to project.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns A value in [0, 1] representing the position along arc closest to p.

copystatic

static copy(arc: Arc | ShapeLike, result?: Arc | null): Arc

Creates a copy of the specified arc.

arc
The arc to copy.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns A copy of arc.

directionAtstatic

static directionAt(arc: Arc | ShapeLike, ratio: Real | NumberLike, result?: Vector | null): Vector

Computes the tangent direction at a normalized position along the arc. The direction always points in the direction of travel.

arc
The arc to sample.
ratio
A value in [0, 1] where 0 is the start and 1 is the end of the arc.
result optional
Optional Vector to write the result into; it is returned. Without it, a new Vector is returned.

Returns The tangent direction at the specified ratio along arc.

distanceTostatic

static distanceTo(arc: Arc | ShapeLike, p: Point | VectorLike, result?: Real | null): Real

Computes the shortest distance from a point to the arc.

arc
The arc to measure against.
p
The point to measure from.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The minimum distance from p to any point on arc.

endDirectionstatic

static endDirection(arc: Arc | ShapeLike, result?: Vector | null): Vector

Returns the tangent direction at the end of the arc.

arc
The arc to query.
result optional
Optional Vector to write the result into; it is returned. Without it, a new Vector is returned.

Returns The tangent direction at the end point of arc.

endPointstatic

static endPoint(arc: Arc | ShapeLike, result?: Point | null): Point

Returns the end point of the arc.

arc
The arc to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The last point of arc.

inflatestatic

static inflate(arc: Arc | ShapeLike, delta: Real | NumberLike, result?: Arc | null): Arc

Returns an arc with the same center and angular range as the specified arc, with its radius adjusted by a given delta.

arc
The arc to inflate.
delta
The amount by which to grow the radius. Negative values shrink the arc.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc with the same center and sweep as arc and a radius increased by delta.

isClockwisestatic

static isClockwise(arc: Arc | ShapeLike, result?: Bool | null): Bool

Determines whether the arc travels in the clockwise direction.

arc
The arc to query.
result optional
Optional Bool to write the result into; it is returned. Without it, a new Bool is returned.

Returns true if arc travels clockwise; otherwise false.

lenstatic

static len(arc: Arc | ShapeLike, result?: Real | null): Real

Computes the arc length of the arc.

arc
The arc to measure.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The total path length along arc.

midPointstatic

static midPoint(arc: Arc | ShapeLike, result?: Point | null): Point

Returns the mid point of the arc, which is the point at ratio 0.5.

arc
The arc to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The point at the midpoint of arc.

normalAtstatic

static normalAt(arc: Arc | ShapeLike, ratio: Real | NumberLike, left: boolean, result?: Vector | null): Vector

Computes the normal direction at a normalized position along the arc. The normal is perpendicular to the tangent at that position.

arc
The arc to sample.
ratio
A value in [0, 1] where 0 is the start and 1 is the end of the arc.
left
If true, the normal points to the left of the travel direction; otherwise to the right.
result optional
Optional Vector to write the result into; it is returned. Without it, a new Vector is returned.

Returns The normal direction at the specified ratio along arc.

pinAtstatic

static pinAt(arc: Arc | ShapeLike, ratio: Real | NumberLike, result?: Pin | null): Pin

Computes the pin (point with orientation) at a normalized position along the arc.

arc
The arc to sample.
ratio
A value in [0, 1] where 0 is the start and 1 is the end of the arc.
result optional
Optional Pin to write the result into; it is returned. Without it, a new Pin is returned.

Returns The pin on arc at the specified ratio, with orientation aligned to the tangent.

pointAtstatic

static pointAt(arc: Arc | ShapeLike, ratio: Real | NumberLike, result?: Point | null): Point

Computes the point at a normalized position along the arc.

arc
The arc to sample.
ratio
A value in [0, 1] where 0 is the start and 1 is the end of the arc.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The point on arc at the specified ratio.

radiusstatic

static radius(arc: Arc | ShapeLike, result?: Real | null): Real

Returns the radius of the arc.

arc
The arc to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The radius of the underlying circle of arc.

reversestatic

static reverse(arc: Arc | ShapeLike, result?: Arc | null): Arc

Returns an arc with the same path but opposite travel direction. The start and end points are swapped; the mid point is preserved.

arc
The arc to reverse.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc traversing the same path as arc in the opposite direction.

scalestatic

static scale(arc: Arc | ShapeLike, factor: Real | NumberLike, result?: Arc | null): Arc

Returns an arc scaled around its own center by a given factor.

arc
The arc to scale.
factor
The scaling factor applied to the radius. Values greater than 1 enlarge the arc; values between 0 and 1 shrink it.
result optional
Optional Arc to write the result into; it is returned. Without it, a new Arc is returned.

Returns An arc with the same center and sweep as arc and a radius multiplied by factor.

startAnglestatic

static startAngle(arc: Arc | ShapeLike, result?: Real | null): Real

Returns the start angle of the arc, measured from the positive x-axis.

arc
The arc to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The angle in radians at which arc begins.

startDirectionstatic

static startDirection(arc: Arc | ShapeLike, result?: Vector | null): Vector

Returns the tangent direction at the start of the arc.

arc
The arc to query.
result optional
Optional Vector to write the result into; it is returned. Without it, a new Vector is returned.

Returns The tangent direction at the start point of arc.

startPointstatic

static startPoint(arc: Arc | ShapeLike, result?: Point | null): Point

Returns the start point of the arc.

arc
The arc to query.
result optional
Optional Point to write the result into; it is returned. Without it, a new Point is returned.

Returns The first point of arc.

sweepAnglestatic

static sweepAngle(arc: Arc | ShapeLike, result?: Real | null): Real

Returns the sweep angle of the arc. Positive values indicate a clockwise sweep on screen; negative values indicate a counter-clockwise sweep..

arc
The arc to query.
result optional
Optional Real to write the result into; it is returned. Without it, a new Real is returned.

Returns The signed angular extent of arc in radians.

toCirclestatic

static toCircle(arc: Arc | ShapeLike, result?: Circle | null): Circle

Returns the full circle on which the arc lies.

arc
The arc to convert.
result optional
Optional Circle to write the result into; it is returned. Without it, a new Circle is returned.

Returns The circle passing through the three defining points of arc.