Unbounded ray from a Point
in direction of an
Angle
.
instance.Ray
Instances of Rac
contain a convenience
rac.Ray
function to create Ray
objects from
primitive values. This function also contains ready-made convenience
objects, like rac.Ray.xAxis
, listed under
instance.Ray
.
Example
let rac = new Rac()
let point = rac.Point(55, 77)
let angle = rac.Angle(1/4)
// new instance with constructor
let ray = new Rac.Ray(rac, point, angle)
// or convenience function
let otherRay = rac.Ray(55, 77, 1/4)
- See also:
Constructor
new Ray(rac, start, angle)
Creates a new Ray
instance.
Parameters:
Name | Type | Description |
---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
start |
Rac.Point
|
A |
angle |
Rac.Angle
|
An |
Members
rac :Rac
Instance of Rac
used for drawing and passed along to any created
object.
Methods
angleToPoint(point) → {Rac.Angle}
Returns the angle from this.start
to point
.
When this.start
and point
are considered
equal, returns this.angle
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
arc(radius, endAngleopt, clockwiseopt) → {Rac.Arc}
Returns a new Arc
with center at this.start
, start at this.angle
and the given arc properties.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
radius |
Number
|
The radius of the new |
||
endAngle |
Rac.Angle
|
Number
|
<optional> |
null
|
The end |
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the new |
arcToAngleDistance(radius, angleDistance, clockwiseopt) → {Rac.Arc}
Returns a new Arc
with center at this.start
, start at this.angle
,
and end at the given angleDistance
from this.start
in the
clockwise
orientation.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
radius |
Number
|
The radius of the new |
||
angleDistance |
Rac.Angle
|
Number
|
The angle distance from
|
||
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the new |
distanceToProjectedPoint(point) → {Number}
Returns the distance from this.start
to the projection of point
onto the ray.
The resulting distance is positive when the projected point is towards the direction of the ray, and negative when it is behind.
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
equals(otherRay) → {Boolean}
Returns true
when start
and angle
in both rays are equal;
otherwise returns false
.
When otherRay
is any class other that Rac.Ray
, returns false
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
otherRay |
Rac.Ray
|
A |
inverse() → {Rac.Ray}
Returns a new Ray
pointing towards
angle.inverse()
.
perpendicular(clockwiseopt) → {Rac.Ray}
Returns a new Ray
pointing towards the
perpendicular angle of
angle
in the clockwise
orientation.
- See also:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the perpendicular |
pointAtCanvasEdge() → (nullable) {Rac.Point}
Returns a new Point
located where the ray touches the canvas edge.
When the ray is outside the canvas and pointing away, returns null
since no point in the canvas is possible.
Added to Rac.Ray.prototype
when Rac.P5Drawer
is setup as
rac.drawer
.
pointAtDistance(distance) → {Rac.Point}
Returns a new Point
in the ray at the given distance
from
this.start
. When distance
is negative, the new Point
is calculated
in the inverse direction of angle
.
Parameters:
Name | Type | Description |
---|---|---|
distance |
Number
|
The distance from |
pointAtIntersection(otherRay) → {Rac.Point}
Returns a new Point
at the intersection of this
and otherRay
.
When the rays are parallel, returns null
since no intersection is
possible.
Both rays are considered unbounded lines.
Parameters:
Name | Type | Description |
---|---|---|
otherRay |
Rac.Ray
|
A |
pointAtX(x) → {Rac.Point}
Returns a new Point
located in the ray where the x coordinate is x
.
When the ray is vertical, returns null
since no single point with x
coordinate at x
is possible.
The ray is considered a unbounded line.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
The x coordinate to calculate a point in the ray |
pointAtY(y) → {Rac.Point}
Returns a new Point
located in the ray where the y coordinate is y
.
When the ray is horizontal, returns null
since no single point with y
coordinate at y
is possible.
The ray is considered an unbounded line.
Parameters:
Name | Type | Description |
---|---|---|
y |
Number
|
The y coordinate to calculate a point in the ray |
pointOrientation(point) → {Boolean}
Returns true
when the angle to the given point
is located clockwise
of the ray or false
when located counter-clockwise.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
pointProjection(point) → {Rac.Point}
Returns a new Point
at the projection of point
onto the ray. The
projected point is the closest possible point to point
.
The ray is considered an unbounded line.
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
rayAtCanvasEdge() → (nullable) {Rac.Ray}
Returns a new Ray
that starts at the point where the this
touches
the canvas edge and pointed towards the inside of the canvas.
When the ray is outside the canvas and pointing away, returns null
since no point in the canvas is possible.
Added to Rac.Ray.prototype
when Rac.P5Drawer
is setup as
rac.drawer
.
rayToPoint(point) → {Rac.Ray}
Returns a new Ray
from this.start
to point
.
When this.start
and point
are considered
equal, the new Ray
will use this.angle
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
segment(length) → {Rac.Segment}
Returns a new Segment
using this
and the given length
.
Parameters:
Name | Type | Description |
---|---|---|
length |
Number
|
The length of the new |
segmentToIntersection(otherRay) → {Rac.Segment}
Returns a new Segment
starting at this.start
and ending at the
intersection of this
and otherRay
.
When the rays are parallel, returns null
since no intersection is
possible.
When this.start
and the intersection point are considered
equal, the new Segment
will use
this.angle
.
Both rays are considered unbounded lines.
Parameters:
Name | Type | Description |
---|---|---|
otherRay |
Rac.Ray
|
A |
segmentToPoint(point) → {Rac.Segment}
Returns a new Segment
from this.start
to point
.
When this.start
and point
are considered
equal, the new Segment
will use
this.angle
.
- See also:
Parameters:
Name | Type | Description |
---|---|---|
point |
Rac.Point
|
A |
slope() → (nullable) {Number}
Returns the slope of the ray, or null
if the ray is vertical.
In the line formula y = mx + b
the slope is m
.
text(string, formatopt) → {Rac.Text}
Returns a new Text
located at start
and oriented towards angle
with the given string
and format
.
When format
is provided, the angle for the resulting Text
will
still be set to angle
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string |
String
|
The string of the new |
||
format |
Rac.Text.Format
|
<optional> |
rac.Text.Format.topLeft
|
The format 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 |
Example
rac.Ray(55, 77, 0.2).toString()
// returns: 'Ray((55,77) a:0.2)'
translatePerpendicular(distance, clockwiseopt) → {Rac.Ray}
Returns a new Ray
with start
moved by the given distance toward the
angle.perpendicular()
. All other properties are copied from this
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
distance |
Number
|
The distance to move |
||
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the perpendicular |
translateToAngle(angle, distance) → {Rac.Ray}
Returns a new Ray
with start
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 |
translateToDistance(distance) → {Rac.Ray}
Returns a new Ray
with start
moved along the ray by the given
distance
. All other properties are copied from this
.
When distance
is negative, start
is moved in
the inverse direction of angle
.
Parameters:
Name | Type | Description |
---|---|---|
distance |
Number
|
The distance to move |
withAngle(newAngle) → {Rac.Ray}
Returns a new Ray
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(increment) → {Rac.Ray}
Returns a new Ray
with increment
added to this.angle
.
All other properties are copied from this
.
Parameters:
Name | Type | Description |
---|---|---|
increment |
Rac.Angle
|
Number
|
The angle to add |
withAngleShift(angle, clockwiseopt) → {Rac.Ray}
Returns a new Ray
with angle
set to
this.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 |
withStart(newStart) → {Rac.Ray}
Returns a new Ray
with start
set to newStart
.
All other properties are copied from this
.
Parameters:
Name | Type | Description |
---|---|---|
newStart |
Rac.Point
|
The start for the new |
withX(newX) → {Rac.Ray}
Returns a new Ray
with start.x
set to newX
.
All other properties are copied from this
.
Parameters:
Name | Type | Description |
---|---|---|
newX |
Number
|
The x coordinate for the new |
withY(newY) → {Rac.Ray}
Returns a new Ray
with start.y
set to newY
.
All other properties are copied from this
.
Parameters:
Name | Type | Description |
---|---|---|
newY |
Number
|
The y coordinate for the new |
yIntercept() → (nullable) {Number}
Returns the y-intercept: the point at which the ray, extended in both
directions, intercepts with the y-axis; or null
if the ray is
vertical.
In the line formula y = mx + b
the y-intercept is b
.