Rac. Arc

Arc of a circle from a start to an end angle.

Arcs that have equal start and end angles are considered a complete circle.

Constructor

new Arc(rac, center, radius, start, end, clockwise)

Creates a new Arc instance.

Parameters:
Name Type Description
rac Rac

Instance to use for drawing and creating other objects

center Rac.Point

The center of the arc

radius number

The radius of the arc

start Rac.Angle

An Angle where the arc starts

end Rac.Angle

Ang Angle where the arc ends

clockwise boolean

The orientation of the arc

Members

center :Rac.Point

The center Point of the arc.

clockwise :boolean

The orientiation of the arc.

end :Rac.Angle

The end Angle of the arc. The arc is draw from start to this angle in the clockwise orientation.

When start and end are equal angles the arc is considered a complete circle.

See:

rac :Rac

Instance of Rac used for drawing and passed along to any created object.

radius :number

The radius of the arc.

start :Rac.Angle

The start Angle of the arc. The arc is draw from this angle towards end in the clockwise orientation.

When start and end are equal angles the arc is considered a complete circle.

See:

Methods

angleDistance() → {Rac.Angle}

Returns a new Angle that represents the distance between start and end, in the orientation of the arc.

chordSegment() → {Rac.Segment}

Returns a new Segment from startPoint() to endPoint().

Note that for complete circle arcs this segment will have a length of zero and be pointed towards the perpendicular of start in the arc's orientation.

circumference() → {number}

Returns the length of circumference of the arc considered as a complete circle.

clampToAngles(angle, startInsetopt, endInsetopt) → {Rac.Angle}

Returns the given angle clamped to the range:

[start + startInset, end - endInset]

where the addition happens towards the arc's orientation, and the subtraction against.

When angle is outside the range, returns whichever range limit is closer.

When the sum of the given insets is larger that this.arcDistance() the range for the clamp is imposible to fulfill. In this case the returned value will be the centered between the range limits and still clampled to [start, end].

Parameters:
Name Type Attributes Default Description
angle Rac.Angle | number

An Angle to clamp

startInset Rac.Angle | number <optional>
instance.Angle#zero

The inset for the lower limit of the clamping range

endInset Rac.Angle | number <optional>
instance.Angle#zero

The inset for the higher limit of the clamping range

containsAngle(angle) → {boolean}

Returns true when angle is between start and end in the arc's orientation.

When the arc represents a complete circle, true is always returned.

Parameters:
Name Type Description
angle Rac.Angle | number

An Angle to evaluate

containsProjectedPoint(point) → {boolean}

Returns true when the projection of point in the arc is positioned between start and end in the arc's orientation.

When the arc represents a complete circle, true is always returned.

Parameters:
Name Type Description
point Rac.Point

A Point to evaluate

distanceFromStart(angle) → {Rac.Angle}

Returns a new Angle that represents the angle distance from start to angle in the arc's orientation.

E.g. For a clockwise arc starting at 0.5: distanceFromStart(0.6) is 0.1. For a counter-clockwise arc starting at 0.5: distanceFromStart(0.6) is 0.9.

Parameters:
Name Type Description
angle Rac.Angle | number

An Angle to measure the distance to

divideToArcs(count) → {Array.<Rac.Arc>}

Returns an array containing new Arc objects representing this divided into count arcs, all with the same angle distance.

When count is zero or lower, returns an empty array. When count is 1 returns an arc equivalent to this.

Parameters:
Name Type Description
count number

Number of arcs to divide this into

divideToBeziers(count) → {Rac.Composite}

Returns a new Composite that contains Bezier objects representing the arc divided into count beziers that approximate the shape of the arc.

When count is zero or lower, returns an empty Composite.

See:
Parameters:
Name Type Description
count number

Number of beziers to divide this into

divideToSegments(count) → {Array.<Rac.Segment>}

Returns an array containing new Segment objects representing this divided into count chords, all with the same length.

When count is zero or lower, returns an empty array. When count is 1 returns an arc equivalent to this.chordSegment().

Parameters:
Name Type Description
count number

Number of segments to divide this into

endPoint() → {Rac.Point}

Returns a new Point located where the arc ends.

endRay() → {Rac.Ray}

Returns a new Ray from center towars end.

endSegment() → {Rac.Segment}

Returns a new Segment from center to endPoint().

equals(otherSegment) → {boolean}

Returns true when all members of both arcs are equal.

When otherArc is any class other that Rac.Arc, returns false.

Arcs' radius are compared using Rac#equals.

See:
Parameters:
Name Type Description
otherSegment Rac.Segment

A Segment to compare

intersectionArc(otherArc) → (nullable) {Rac.Arc}

Returns a new Arc representing the section of this that is inside otherArc, or null when there is no intersection. The returned arc will have the same center, radius, and orientation as this.

Both arcs are considered complete circles for the calculation of the intersection, thus the endpoints of the returned arc may not lay inside this.

An edge case of this method is that when the distance between this and otherArc is the sum of their radius, meaning the arcs touch at a single point, the resulting arc may have a angle-distance of zero, which is interpreted as a complete-circle arc.

Parameters:
Name Type Description
otherArc Rac.Arc

An Arc to intersect with

intersectionChord(otherArc) → (nullable) {Rac.Segment}

Returns a new Segment for the chord formed by the intersection of this and otherArc, or null when there is no intersection.

The returned Segment will point towards the this orientation.

Both arcs are considered complete circles for the calculation of the chord, thus the endpoints of the returned segment may not lay inside the actual arcs.

Parameters:
Name Type Description
otherArc Rac.Arc

description

intersectionChordEndWithRay(ray) → (nullable) {Rac.Point}

Returns a new Point representing the end of the chord formed by the intersection of the arc and 'ray', or null when no chord is possible.

When useProjection is true the method will always return a Point even when there is no contact between the arc and ray. In this case the point in the arc closest to ray is returned.

The arc is considered a complete circle and ray is considered an unbounded line.

Parameters:
Name Type Description
ray Rac.Ray

A Ray to calculate the intersection with

intersectionChordWithRay(ray) → (nullable) {Rac.Segment}

Returns a new Segment representing the chord formed by the intersection of the arc and 'ray', or null when no chord is possible.

The returned Segment will always have the same angle as ray.

The arc is considered a complete circle and ray is considered an unbounded line.

Parameters:
Name Type Description
ray Rac.Ray

A Ray to calculate the intersection with

isCircle() → {boolean}

Returns true if the arc is a complete circle, which is when start and end are equal angles.

See:

length() → {number}

Returns the length of the arc: the part of the circumference the arc represents.

pointAtAngle(angle) → {Rac.Point}

Returns a new Point located in the arc at the given angle. This method does not consider the start nor end of the arc.

The arc is considered a complete circle.

Parameters:
Name Type Description
angle Rac.Angle | number

An Angle towards the new Point

pointAtAngleDistance(angle) → {Rac.Point}

Returns a new Point located in the arc at the given angle shifted by start in arc's orientation.

The arc is considered a complete circle.

Parameters:
Name Type Description
angle Rac.Angle

An Angle to be shifted by start

pointAtLength(length) → {Rac.Point}

Returns a new Point located in the arc at the given length from startPoint() in arc's orientation.

The arc is considered a complete circle.

Parameters:
Name Type Description
length number

The length from startPoint() to the new Point

pointAtLengthRatio(ratio) → {Rac.Point}

Returns a new Point located in the arc at length() * ratio from startPoint() in the arc's orientation.

The arc is considered a complete circle.

Parameters:
Name Type Description
ratio number

The factor to multiply length() by

radiusSegmentAtAngle(angle) → {Rac.Segment}

Returns a new Segment representing the radius of the arc at the given angle. This method does not consider the start nor end of the arc.

The arc is considered a complete circle.

Parameters:
Name Type Description
angle Rac.Angle | number

The direction of the radius to return

radiusSegmentTowardsPoint(point) → {Rac.Segment}

Returns a new Segment representing the radius of the arc in the direction towards the given point. This method does not consider the start nor end of the arc.

The arc is considered a complete circle.

Parameters:
Name Type Description
point Rac.point

A Point in the direction of the radius to return

reverse() → {Rac.Arc}

Returns a new Arc with its start and end exchanged, and the opposite clockwise orientation. The center and radius remain be the same as this.

shiftAngle(angle) → {Rac.Angle}

Returns a new Angle with angle shifted by start in the arc's orientation.

E.g. For a clockwise arc starting at 0.5: shiftAngle(0.1) is 0.6. For a counter-clockwise arc starting at 0.5: shiftAngle(0.1) is 0.4.

See:
Parameters:
Name Type Description
angle Rac.Angle | number

An Angle to shift

startPoint() → {Rac.Point}

Returns a new Point located where the arc starts.

startRay() → {Rac.Ray}

Returns a new Ray from center towars start.

startSegment() → {Rac.Segment}

Returns a new Segment from center to startPoint().

tangentSegment(otherArc, startClockwise, endClockwise) → (nullable) {Rac.Segment}

Returns a new Segment that is tangent to both this and otherArc, or null when no tangent segment is possible. The new Segment starts at the contact point with this and ends at the contact point with otherArc.

Considering center axis a ray from this.center towards otherArc.center, startClockwise determines the side of the start point of the returned segment in relation to center axis, and endClockwise the side of the end point.

Both this and otherArc are considered complete circles.

Parameters:
Name Type Default Description
otherArc Rac.Arc

An Arc to calculate a tangent segment towards

startClockwise boolean true

The orientation of the new Segment start point in relation to the center axis

endClockwise boolean true

The orientation of the new Segment end point in relation to the center axis

toString(digitsopt) → {string}

Returns a string representation intended for human consumption.

Parameters:
Name Type Attributes Default Description
digits number <optional>
null

The number of digits to print after the decimal point, when ommited all digits are printed

withAngleDistance(angleDistance) → {Rac.Arc}

Returns a new Arc with the given angleDistance as the distance between start and end in the arc's orientation. This changes end for the new Arc.

All other properties are copied from this.

See:
Parameters:
Name Type Description
angleDistance Rac.Angle | number

The angle distance of the new Arc

withAnglesTowardsPoint(startPoint, endPointopt, nullable) → {Rac.Arc}

Returns a new Arc with start pointing towards startPoint and end pointing towards endPoint, both from center.

All other properties are copied from this.

  • When center is considered equal to either startPoint or endPoint, the new Arc will use this.start or this.end respectively.
See:
Parameters:
Name Type Attributes Default Description
startPoint Rac.Point

A Point to point start towards

endPoint Rac.Point <optional>
<nullable>
null

A Point to point end towards; when ommited or null, startPoint is used instead

withCenter(newCenter) → {Rac.Arc}

Returns a new Arc with center set to newCenter.

All other properties are copied from this.

Parameters:
Name Type Description
newCenter Rac.Point

The center for the new Arc

withClockwise(newClockwise) → {Rac.Arc}

Returns a new Arc with its orientation set to newClockwise.

All other properties are copied from this.

Parameters:
Name Type Description
newClockwise boolean

The orientation for the new Arc

withEnd(newEnd) → {Rac.Arc}

Returns a new Arc with end set to newEnd.

All other properties are copied from this.

Parameters:
Name Type Description
newEnd Rac.Angle | number

The end for the new Arc

withEndExtension(angle) → {Rac.Arc}

Returns a new Arc with end shifted by the given angle in the arc's orientation.

All other properties are copied from this.

Notice that this method shifts end towards the arc's orientation, intending to result in a new Arc with an increase to angleDistance().

Parameters:
Name Type Description
angle Rac.Angle

An Angle to shift start against

withEndPoint(point) → {Rac.Arc}

Returns a new Arc with endPoint() located at point. This changes end and radius in the new Arc.

All other properties are copied from this.

When center and point are considered equal, the new Arc will use this.end.

See:
Parameters:
Name Type Description
point Rac.Point

A Point at the endPoint() of the new Arc`

withEndTowardsPoint(point) → {Rac.Arc}

Returns a new Arc with end pointing towards point from center.

All other properties are copied from this.

When center and point are considered equal, the new Arc will use this.end.

See:
Parameters:
Name Type Description
point Rac.Point

A Point to point end towards

withLength(length) → {Rac.Arc}

Returns a new Arc with the given length as the length of the part of the circumference it represents. This changes end for the new Arc.

All other properties are copied from this.

The actual length() of the resulting Arc will always be in the range [0,radius*TAU). When the given length is larger that the circumference of the arc as a complete circle, the resulting arc length will be cut back into range through a modulo operation.

See:
Parameters:
Name Type Description
length number

The length of the new Arc

withLengthAdd(length) → {Rac.Arc}

Returns a new Arc with length added to the part of the circumference this represents. This changes end for the new Arc.

All other properties are copied from this.

The actual length() of the resulting Arc will always be in the range [0,radius*TAU). When the resulting length is larger that the circumference of the arc as a complete circle, the resulting arc length will be cut back into range through a modulo operation.

See:
Parameters:
Name Type Description
length number

The length to add

withLengthRatio(ratio) → {Rac.Arc}

Returns a new Arc with a length() of this.length() * ratio. This changes end for the new Arc.

All other properties are copied from this.

The actual length() of the resulting Arc will always be in the range [0,radiusTAU)*. When the calculated length is larger that the circumference of the arc as a complete circle, the resulting arc length will be cut back into range through a modulo operation.

See:
Parameters:
Name Type Description
ratio number

The factor to multiply length() by

withRadius(newRadius) → {Rac.Arc}

Returns a new Arc with radius set to newRadius.

All other properties are copied from this.

Parameters:
Name Type Description
newRadius number

The radius for the new Arc

withStart(newStart) → {Rac.Arc}

Returns a new Arc with start set to newStart.

All other properties are copied from this.

Parameters:
Name Type Description
newStart Rac.Angle | number

The start for the new Arc

withStartExtension(angle) → {Rac.Arc}

Returns a new Arc with start shifted by the given angle in the arc's opposite orientation.

All other properties are copied from this.

Notice that this method shifts start to the arc's opposite orientation, intending to result in a new Arc with an increase to angleDistance().

Parameters:
Name Type Description
angle Rac.Angle

An Angle to shift start against

withStartPoint(point) → {Rac.Arc}

Returns a new Arc with startPoint() located at point. This changes start and radius for the new Arc.

All other properties are copied from this.

When center and point are considered equal, the new Arc will use this.start.

See:
Parameters:
Name Type Description
point Rac.Point

A Point at the startPoint() of the new Arc`

withStartTowardsPoint(point) → {Rac.Arc}

Returns a new Arc with start pointing towards point from center.

All other properties are copied from this.

When center and point are considered equal, the new Arc will use this.start.

See:
Parameters:
Name Type Description
point Rac.Point

A Point to point start towards