Skip to content

Arc

Overview

A circular arc (a continuous sub-part of a circle).

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class Arc

import { Arc } from 'scenerystack/kite';

Constructor

new Arc( center : Vector2, radius : number, startAngle : number, endAngle : number, anticlockwise : boolean )

Instance Methods

setCenter( center : Vector2 ) : this

Sets the center of the Arc.

getCenter() : Vector2

Returns the center of this Arc.

setRadius( radius : number ) : this

Sets the radius of the Arc.

getRadius() : number

Returns the radius of this Arc.

setStartAngle( startAngle : number ) : this

Sets the startAngle of the Arc.

getStartAngle() : number

Returns the startAngle of this Arc.

setEndAngle( endAngle : number ) : this

Sets the endAngle of the Arc.

getEndAngle() : number

Returns the endAngle of this Arc.

setAnticlockwise( anticlockwise : boolean ) : this

Sets the anticlockwise of the Arc.

getAnticlockwise() : boolean

Returns the anticlockwise of this Arc.

positionAt( t : number ) : Vector2

Returns the position parametrically, with 0 <= t <= 1.

NOTE: positionAt( 0 ) will return the start of the segment, and positionAt( 1 ) will return the end of the segment.

This method is part of the Segment API. See Segment.js's constructor for more API documentation.

tangentAt( t : number ) : Vector2

Returns the non-normalized tangent (dx/dt, dy/dt) of this segment at the parametric value of t, with 0 <= t <= 1.

NOTE: tangentAt( 0 ) will return the tangent at the start of the segment, and tangentAt( 1 ) will return the tangent at the end of the segment.

This method is part of the Segment API. See Segment.js's constructor for more API documentation.

curvatureAt( t : number ) : number

Returns the signed curvature of the segment at the parametric value t, where 0 <= t <= 1.

The curvature will be positive for visual clockwise / mathematical counterclockwise curves, negative for opposite curvature, and 0 for no curvature.

NOTE: curvatureAt( 0 ) will return the curvature at the start of the segment, and curvatureAt( 1 ) will return the curvature at the end of the segment.

This method is part of the Segment API. See Segment.js's constructor for more API documentation.

subdivided( t : number ) : Arc[]

Returns an array with up to 2 sub-segments, split at the parametric t value. Together (in order) they should make up the same shape as the current segment.

This method is part of the Segment API. See Segment.js's constructor for more API documentation.

invalidate()

Clears cached information, should be called when any of the 'constructor arguments' are mutated.

getStart() : Vector2

Gets the start position of this arc.

getEnd() : Vector2

Gets the end position of this arc.

getStartTangent() : Vector2

Gets the unit vector tangent to this arc at the start point.

getEndTangent() : Vector2

Gets the unit vector tangent to the arc at the end point.

getActualEndAngle() : number

Gets the end angle in radians.

getIsFullPerimeter() : boolean

Returns a boolean value that indicates if the arc wraps up by more than two Pi.

getAngleDifference() : number

Returns an angle difference that represents how "much" of the circle our arc covers.

The answer is always greater or equal to zero The answer can exceed two Pi

getBounds() : Bounds2

Returns the bounds of this segment.

getNondegenerateSegments() : Arc[]

Returns a list of non-degenerate segments that are equivalent to this segment. Generally gets rid (or simplifies) invalid or repeated segments.

mapAngle( angle : number ) : number

Maps a contained angle to between [startAngle,actualEndAngle), even if the end angle is lower.

tAtAngle( angle : number ) : number

Returns the parametrized value t for a given angle. The value t should range from 0 to 1 (inclusive).

angleAt( t : number ) : number

Returns the angle for the parametrized t value. The t value should range from 0 to 1 (inclusive).

positionAtAngle( angle : number ) : Vector2

Returns the position of this arc at angle.

tangentAtAngle( angle : number ) : Vector2

Returns the normalized tangent of this arc. The tangent points outward (inward) of this arc for clockwise (anticlockwise) direction.

containsAngle( angle : number ) : boolean

Returns whether the given angle is contained by the arc (whether a ray from the arc's origin going in that angle will intersect the arc).

getSVGPathFragment() : string

Returns a string containing the SVG path. assumes that the start point is already provided, so anything that calls this needs to put the M calls first

strokeLeft( lineWidth : number ) : Arc[]

Returns an array of arcs that will draw an offset on the logical left side

strokeRight( lineWidth : number ) : Arc[]

Returns an array of arcs that will draw an offset curve on the logical right side

getInteriorExtremaTs() : number[]

Returns a list of t values where dx/dt or dy/dt is 0 where 0 < t < 1. subdividing on these will result in monotonic segments Does not include t=0 and t=1

intersection( ray : Ray2 ) : RayIntersection[]

Hit-tests this segment with the ray. An array of all intersections of the ray with this segment will be returned. For details, see the documentation in Segment.js

windingIntersection( ray : Ray2 ) : number

Returns the resultant winding number of this ray intersecting this arc.

writeToContext( context : CanvasRenderingContext2D )

Draws this arc to the 2D Canvas context, assuming the context's current location is already at the start point

transformed( matrix : Matrix3 ) : Arc | EllipticalArc

Returns a new copy of this arc, transformed by the given matrix.

TODO: test various transform types, especially rotations, scaling, shears, etc. https://github.com/phetsims/kite/issues/76

getSignedAreaFragment() : number

Returns the contribution to the signed area computed using Green's Theorem, with P=-y/2 and Q=x/2.

NOTE: This is this segment's contribution to the line integral (-y/2 dx + x/2 dy).

reversed() : Arc

Returns a reversed copy of this segment (mapping the parametrization from [0,1] => [1,0]).

getArcLength() : number

Returns the arc length of the segment.

toPiecewiseLinearOrArcSegments() : Segment[]

We can handle this simply by returning ourselves.

serialize() : SerializedArc

Returns an object form that can be turned back into a segment with the corresponding deserialize method.

getOverlaps( segment : Segment, epsilon ) : Overlap[] | null

Determine whether two lines overlap over a continuous section, and if so finds the a,b pair such that p( t ) === q( a * t + b ).

@param segment @param [epsilon] - Will return overlaps only if no two corresponding points differ by this amount or more in one component. @returns - The solution, if there is one (and only one)

getConicMatrix() : Matrix3

Returns the matrix representation of the conic section of the circle. See https://en.wikipedia.org/wiki/Matrix_representation_of_conic_sections

Static Methods

deserialize( obj : SerializedArc ) : Arc

Returns an Arc from the serialized representation.

computeActualEndAngle( startAngle : number, endAngle : number, anticlockwise : boolean ) : number

Determines the actual end angle (compared to the start angle).

Normalizes the sign of the angles, so that the sign of ( endAngle - startAngle ) matches whether it is anticlockwise.

getAngularOverlaps( startAngle1 : number, endAngle1 : number, startAngle2 : number, endAngle2 : number ) : Overlap[]

Determine whether two Arcs overlap over continuous sections, and if so finds the a,b pairs such that p( t ) === q( a * t + b ).

@param startAngle1 - Start angle of arc 1 @param endAngle1 - "Actual" end angle of arc 1 @param startAngle2 - Start angle of arc 2 @param endAngle2 - "Actual" end angle of arc 2 @returns - Any overlaps (from 0 to 2)

getOverlaps( arc1 : Arc, arc2 : Arc ) : Overlap[]

Determine whether two Arcs overlap over continuous sections, and if so finds the a,b pairs such that p( t ) === q( a * t + b ).

@returns - Any overlaps (from 0 to 2)

getCircleIntersectionPoint( center1 : Vector2, radius1 : number, center2 : Vector2, radius2 : number ) : Vector2[]

Returns the points of intersections between two circles.

@param center1 - Center of the first circle @param radius1 - Radius of the first circle @param center2 - Center of the second circle @param radius2 - Radius of the second circle

intersect( a : Arc, b : Arc ) : SegmentIntersection[]

Returns any (finite) intersection between the two arc segments.

createFromPoints( startPoint : Vector2, middlePoint : Vector2, endPoint : Vector2 ) : Segment

Creates an Arc (or if straight enough a Line) segment that goes from the startPoint to the endPoint, touching the middlePoint somewhere between the two.

Type SerializedArc

import type { SerializedArc } from 'scenerystack/kite';
  • type: "Arc"
  • centerX: number
  • centerY: number
  • radius: number
  • startAngle: number
  • endAngle: number
  • anticlockwise: boolean

Source Code

See the source for Arc.ts in the kite repository.