Constructor
new Segment(rac, ray, length)
Creates a new Segment instance.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
ray |
Rac.Ray
|
A |
length |
number
|
The length of the segment |
Members
rac :Rac
Instance of Rac used for drawing and passed along to any created
object.
Methods
angle() → {Rac.Angle}
Returns the angle of the segment's ray.
arc(endAngleopt, nullable, clockwiseopt) → {Rac.Arc}
Returns a new Arc based on this segment, with the given endAngle
and clockwise orientation.
The returned Arc will use this segment's start as center, its angle
as start, and its length as radius.
When endAngle is ommited or null, the segment's angle is used
instead resulting in a complete-circle arc.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
endAngle |
Rac.Angle
|
<optional> <nullable> |
null |
An |
clockwise |
boolean
|
<optional> |
true |
The orientation of the new |
arcWithAngleDistance(angleDistance, clockwiseopt) → {Rac.Arc}
Returns a new Arc based on this segment, with the arc's end at
angleDistance from the segment's angle in the clockwise
orientation.
The returned Arc will use this segment's start as center, its angle
as start, and its length as radius.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angleDistance |
Rac.Angle
|
number
|
The angle distance from the
segment's start to the new |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the new |
clampToLength(value, startInsetopt, endInsetopt) → {number}
Returns the given value clamped to [startInset, length-endInset].
When startInset is greater that length-endInset the range for the
clamp becomes imposible to fulfill. In this case the returned value
will be the centered between the range limits and still clampled to
[0, length].
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
value |
number
|
A value to clamp |
||
startInset |
number
|
<optional> |
0 |
The inset for the lower limit of the clamping range |
endInset |
endInset
|
<optional> |
0 |
The inset for the higher limit of the clamping range |
endPoint() → {Rac.Point}
Returns a new Point where the segment ends.
equals(otherSegment) → {boolean}
Returns true when ray and length in both segments are equal;
otherwise returns false.
When otherSegment is any class other that Rac.Segment, returns false.
Segments' length are compared using Rac#equals.
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
otherSegment |
Rac.Segment
|
A |
inverse() → {Rac.Segment}
Returns a new Segment poiting towards the
inverse angle of this.angle().
The resulting Segment will have the same startPoint() and length
as this.
- See:
moveEndPoint(newEndPoint) → {Rac.Segment}
Returns a new Segment starting at this.startPoint() and ending at
newEndPoint.
When this.startPoint() and newEndPoint are considered
equal, the new Segment will use
this.angle().
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
newEndPoint |
Rac.Point
|
The end point of the new |
moveStartPoint(newStartPoint) → {Rac.Segment}
Returns a new Segment starting at newStartPoint and ending at
this.endPoint().
When newStartPoint and this.endPoint() are considered
equal, the new Segment will use
this.angle().
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
newStartPoint |
Rac.Point
|
The start point of the new |
nextSegmentLegWithHyp(hypotenuse, clockwiseopt) → {Rac.Segment}
Returns a new Segment starting from endPoint() which corresponds
to the leg of a right triangle where this is the other cathetus and
the hypotenuse is of length hypotenuse.
The new Segment will point towards the perpendicular angle of
this.angle().[inverse() in the clockwise
orientation.
When hypotenuse is smaller that the segment's length, returns
null since no right triangle is possible.
- See:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
hypotenuse |
number
|
The length of the hypotenuse side of the
right triangle formed with |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the
perpendicular angle from |
nextSegmentPerpendicular(clockwiseopt, lengthopt, nullable) → {Rac.Segment}
Returns a new Segment starting from endPoint() towards the
perpendicular angle of
this.angle().inverse() in the clockwise orientation.
The new Segment will have the given length, or when ommited or
null will use this.length instead.
Notice that the perpendicular is calculated from the inverse of the
segment's angle. E.g. with clockwise as true, the resulting
Segment will be pointing towards this.angle().perpendicular(false).
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clockwise |
boolean
|
<optional> |
true |
The orientation of the
perpendicular angle from |
length |
number
|
<optional> <nullable> |
null |
The length of the new |
nextSegmentToAngle(angle, lengthopt, nullable) → {Rac.Segment}
Returns a new Segment starting from endPoint() towards angle
with the given length.
The new Segment will have the given length, or when ommited or
null will use this.length instead.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angle |
Rac.Angle
|
number
|
The angle of the new |
||
length |
number
|
<optional> <nullable> |
null |
The length of the new |
nextSegmentToAngleDistance(angleDistance, clockwiseopt, lengthopt, nullable) → {Rac.Segment}
Returns a new Segment starting from endPoint() towards the given
angleDistance from this.angle().inverse() in the clockwise
orientation.
The new Segment will have the given length, or when ommited or
null will use this.length instead.
Notice that the angleDistance is applied to the inverse of the
segment's angle. E.g. with an angleDistance of 0 the resulting
Segment will be directly over and pointing in the inverse angle of
this. As the angleDistance increases the two segments separate with
the pivot at endPoint().
- See:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angleDistance |
Rac.Angle
|
number
|
An angle distance to apply to the segment's angle inverse |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the angle shift
from |
length |
number
|
<optional> <nullable> |
null |
The length of the new |
nextSegmentToPoint(nextEndPoint) → {Rac.Segment}
Returns a new Segment starting from endPoint() and up to the given
nextEndPoint.
When endPoint() and nextEndPoint are considered
equal, the new Segment will use
this.angle().
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
nextEndPoint |
Rac.Point
|
The end point of the next |
nextSegmentWithLength(length) → {Rac.Segment}
Returns a new Segment starting from endPoint() with the given
length and the same angle as this.
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number
|
The length of the next |
perpendicular(clockwiseopt) → {Rac.Segment}
Returns a new Segment pointing towards the
perpendicular angle of
this.angle() in the clockwise orientation.
The resulting Segment will have the same startPoint() and length
as this.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
clockwise |
boolean
|
<optional> |
true |
The orientation of the perpendicular |
pointAtBisector() → {Rac.Point}
Returns a new Point at the middle point the segment.
pointAtLength(length) → {Rac.Point}
Returns a new Point in the segment's ray at the given length from
this.startPoint(). When length is negative, the new Point is
calculated in the inverse direction of this.angle().
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number
|
The distance from |
pointAtLengthRatio(ratio) → {Rac.Point}
Returns a new Point in the segment's ray at a distance of
this.length * ratio from this.startPoint(). When ratio is
negative, the new Point is calculated in the inverse direction of
this.angle().
Parameters:
| Name | Type | Description |
|---|---|---|
ratio |
number
|
The factor to multiply |
reverse() → {Rac.Segment}
Returns a new Segment with its start point set at
this.endPoint(),
angle set to this.angle().inverse(), and
same length as this.
- See:
segmentBisector(lengthopt, nullable, clockwiseopt) → {Rac.Segment}
Returns a new Segment from the segment's middle point towards the
perpendicular angle in the clockwise orientation.
The new Segment will have the given length, or when ommited or
null will use this.length instead.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
length |
number
|
<optional> <nullable> |
null |
The length of the new |
clockwise |
boolean
|
<optional> |
true |
The orientation of the perpendicular |
segmentToBisector() → {Rac.Segment}
Returns a new Segment from the starting point to the segment's middle
point.
startPoint() → {Rac.Point}
Returns the start of the segment's ray.
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 |
translatePerpendicular(distance, clockwiseopt) → {Rac.Segment}
Returns a new Segment with the start point moved the given distance
towards the perpendicular angle to this.angle() in the clockwise
orientaton. All other properties are copied from this.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
distance |
number
|
The distance to move the start point by |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the perpendicular |
translateToAngle(angle, distance) → {Rac.Segment}
Returns a new Segment with the start point moved towards angle by
the given distance. All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
number
|
An |
distance |
number
|
The distance to move the start point by |
translateToLength(length) → {Rac.Segment}
Returns a new Segment with the start point moved along the segment's
ray by the given length. All other properties are copied from this.
When length is negative, start is moved in the inverse direction of
angle.
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number
|
The length to move the start point by |
vertex()
Calls p5.vertex to represent this Segment.
Added to Rac.Segment.prototype when Rac.P5Drawer is setup as
rac.drawer.
withAngle(newAngle) → {Rac.Segment}
Returns a new Segment with angle set to newAngle.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
newAngle |
Rac.Angle
|
number
|
The angle for the new |
withAngleAdd(angle) → {Rac.Segment}
Returns a new Segment with angle added to this.angle().
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
number
|
The angle to add |
withAngleShift(angle, clockwiseopt) → {Rac.Segment}
Returns a new Segment with angle set to
this.ray.angle.shift(angle, clockwise).
All other properties are copied from this.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
angle |
Rac.Angle
|
number
|
The angle to be shifted by |
||
clockwise |
boolean
|
<optional> |
true |
The orientation of the shift |
withEndExtension(distance) → {Rac.Segment}
Returns a new Segment with distance added to this.length, which
results in endPoint() for the resulting Segment moving in the
direction of the segment's ray by the given distance.
All other properties are copied from this.
Using a positive distance results in a longer segment, using a
negative distance results in a shorter one.
This method performs the same operation as
withLengthAdd.
Parameters:
| Name | Type | Description |
|---|---|---|
distance |
number
|
The distance to add to |
withLength(newLength) → {Rac.Segment}
Returns a new Segment with length set to newLength.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
newLength |
number
|
The length for the new |
withLengthAdd(length) → {Rac.Segment}
Returns a new Segment with length added to this.length.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
length |
number
|
The length to add |
withLengthRatio(ratio) → {Rac.Segment}
Returns a new Segment with length set to this.length * ratio.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
ratio |
number
|
The factor to multiply |
withRay(newRay) → {Rac.Segment}
Returns a new Segment with ray set to newRay.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
newRay |
Rac.Ray
|
The ray for the new |
withStartExtension(distance) → {Rac.Segment}
Returns a new Segment with the start point moved in the inverse
direction of the segment's ray by the given distance. The resulting
Segment will have the same endPoint() and angle() as this.
Using a positive distance results in a longer segment, using a
negative distance results in a shorter one.
Parameters:
| Name | Type | Description |
|---|---|---|
distance |
number
|
The distance to move the start point by |
withStartPoint(newStartPoint) → {Rac.Segment}
Returns a new Segment with start point set to newStart.
All other properties are copied from this.
Parameters:
| Name | Type | Description |
|---|---|---|
newStartPoint |
Rac.Point
|
The start point for the new
|