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 |
end |
Rac.Angle
|
Ang |
clockwise |
Boolean
|
The orientation of the arc |
Members
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.
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 |
||
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 |
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 |
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 |
Examples
let arc = rac.Arc(55, 77, 0.5, null, true)
// returns 0.2, since 0.7 - 0.5 = 0.2
arc.distanceFromStart(0.7)
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 |
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 |
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 |
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, 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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
angle |
Rac.Angle
|
Number
|
An |
Examples
let arc = rac.Arc(0, 0, 0.5, null, true)
// returns 0.6, since 0.5 + 0.1 = 0.6
arc.shiftAngle(0.1)
let arc = rac.Arc(0, 0, 0.5, null, false)
// returns 0.3, since 0.5 - 0.2 = 0.3
arc.shiftAngle(0.2)
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 |
|
startClockwise |
Boolean
|
true
|
The orientation of the new |
endClockwise |
Boolean
|
true
|
The orientation of the new |
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 also:
Parameters:
Name | Type | Description |
---|---|---|
angleDistance |
Rac.Angle
|
Number
|
The angle distance of the
new |
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 eitherstartPoint
orendPoint
, the newArc
will usethis.start
orthis.end
respectively.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
startPoint |
Rac.Point
|
A |
||
endPoint |
Rac.Point
|
<optional> <nullable> |
null
|
A |
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 |
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 |
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 |
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 |
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 |
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 |
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 also:
Parameters:
Name | Type | Description |
---|---|---|
length |
Number
|
The length of the new |
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 also:
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 also:
Parameters:
Name | Type | Description |
---|---|---|
ratio |
Number
|
The factor to multiply |
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 |
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 |
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 |
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 |
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 |