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.

instance.Arc

Instances of Rac contain a convenience rac.Arc function to create Arc objects from primitive values. This function also contains ready-made convenience objects, like rac.Arc.zero, listed under instance.Arc.

Example
let rac = new Rac()
let center = rac.Point(55, 77)
let start = rac.Angle(1/8)
let end = rac.Angle(3/8)
// new instance with constructor
let arc = new Rac.Arc(rac, center, 100, start, end, true)
// or convenience function
let otherArc = rac.Arc(55, 77, 1/8, 3/8)
See also:

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 also:

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 also:

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>
rac.Angle.zero

The inset for the lower limit of the clamping range

endInset Rac.Angle | Number <optional>
rac.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.

Can be used to determine, for a given angle, where it sits inside the arc if the arc start was the origin angle.

Parameters:
Name Type Description
angle Rac.Angle | Number

An Angle to measure the distance to

Examples

For a clockwise arc starting at 0.5

let arc = rac.Arc(55, 77, 0.5, null, true)
// returns 0.2, since 0.7 - 0.5 = 0.2
arc.distanceFromStart(0.7)

For a counter-clockwise arc starting at 0.5

let arc = rac.Arc(55, 77, 0.5, null, false)
// returns 0.8, since 1 - (0.7 - 0.5) = 0.8
arc.distanceFromStart(0.7)

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 also:
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.

endRadiusSegment() → {Rac.Segment}

Returns a new Segment representing the radius of the arc at end. The segment starts starts at center and ends at endPoint().

endRay() → {Rac.Ray}

Returns a new Ray from center towars end.

endSegment() → {Rac.Segment}

Returns a new Segment representing the radius of the arc at end. The segment starts starts at center and ends at endPoint().

Equivalent to endRadiusSegment.

endTangentRay()

Returns a new Ray tangent to the arc starting at endPoint() and against the arc's orientation.

equals(otherSegment) → {Boolean}

Returns true when all members, except rac, of both arcs are equal; otherwise returns false.

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

Arcs' radius are compared using Rac#equals.

See also:
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 resulting Segment will point towards 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 resulting 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 also:

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 towards the arc's orientation.

For this operation the arc is considered a complete circle, the returned Point may be outside the arc's bounds.

See also:
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 the same as this.

shift(angle) → {Rac.Arc}

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

Notice that this method shifts both start and end towards the arc's orientation, resulting in a new Arc with the same angleDistance().

See also:
Parameters:
Name Type Description
angle Rac.Angle | Number

An Angle to shift the arc by

Examples

For a clockwise arc

let arc = rac.Arc(0, 0, 0.4, 0.6, true)
let shiftedArc = arc.shift(0.1)
shiftedArc.start.turn // returns 0.5
shiftedArc.end.turn   // returns 0.7

For a counter-clockwise arc

let arc = rac.Arc(0, 0, 0.4, 0.6, false)
let shiftedArc = arc.shift(0.1)
shiftedArc.start.turn // returns 0.3
shiftedArc.end.turn   // returns 0.5

shiftAngle(angle) → {Rac.Angle}

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

See also:
Parameters:
Name Type Description
angle Rac.Angle | Number

An Angle to shift

Examples

For a clockwise arc starting at 0.5

let arc = rac.Arc(0, 0, 0.5, null, true)
arc.shiftAngle(0.1).turn
// returns 0.6, since 0.5 + 0.1 = 0.6

For a counter-clockwise arc starting at 0.5

let arc = rac.Arc(0, 0, 0.5, null, false)
arc.shiftAngle(0.1).turn
// returns 0.4, since 0.5 - 0.1 = 0.4

startPoint() → {Rac.Point}

Returns a new Point located where the arc starts.

startRadiusSegment() → {Rac.Segment}

Returns a new Segment representing the radius of the arc at start. The segment starts starts at center and ends at startPoint().

startRay() → {Rac.Ray}

Returns a new Ray from center towars start.

startSegment() → {Rac.Segment}

Returns a new Segment representing the radius of the arc at start. The segment starts starts at center and ends at startPoint().

Equivalent to startRadiusSegment.

startTangentRay()

Returns a new Ray tangent to the arc starting at startPoint() and towards the arc's orientation.

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

text(string, formatopt) → {Rac.Text}

Returns a new Text located and oriented towards startTangentRay() with the given string and format.

When format is ommited or null, the format used for the resulting Text will be:

When format is provided, the angle for the resulting Text will still be set to startTangentRay().angle.

Parameters:
Name Type Attributes Default Description
string String

The string of the new Text

format Rac.Text.Format <optional>
rac.Text.Format.topLeft

The format of the new Text; when ommited or null, a default format is used instead

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

Example
rac.Arc(55, 77, 0.2, 0.4, 100).toString()
// returns: 'Arc((55,77) r:100 s:0.2 e:0.4 c:true)'

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 also:
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 also:
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 towards the arc's orientation.

All other properties are copied from this.

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

See also:
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 also:
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 also:
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 reduced into range through a modulo operation.

See also:
Parameters:
Name Type Description
length Number

The length of the new Arc

withLengthAdd(increment) → {Rac.Arc}

Returns a new Arc with increment 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 reduced into range through a modulo operation.

See also:
Parameters:
Name Type Description
increment 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 reduced into range through a modulo operation.

See also:
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 towards the arc's opposite orientation.

All other properties are copied from this.

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

See also:
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 also:
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 also:
Parameters:
Name Type Description
point Rac.Point

A Point to point start towards