Rac. Ray

Unbounded ray from a Point in direction of an Angle.

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 Point where the ray starts

angle Rac.Angle

An Angle the ray is directed to

Members

angle :Rac.Angle

The angle towards which the ray extends.

rac :Rac

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

start :Rac.Point

The start point of the ray.

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

A Point to measure the angle to

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 Arc

endAngle Rac.Angle | number <optional>
null

The end Angle of the new Arc; when null or ommited, this.angle is used instead

clockwise boolean <optional>
true

The orientation of the new Arc

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 Arc

angleDistance Rac.Angle | number

The angle distance from this.start to the new Arc end

clockwise boolean <optional>
true

The orientation of the new Arc

distanceToProjectedPoint(point) → {number}

Returns the distance from this.start to the projection of point onto the ray.

The returned 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 Point to project and measure the distance to

equals(otherRay) → {boolean}

Returns true when start and angle in both rays are equal.

When otherRay is any class other that Rac.Ray, returns false.

See:
Parameters:
Name Type Description
otherRay Rac.Ray

A Ray to compare

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:
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, null is returned.

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 this.start

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 Ray to calculate the intersection with

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)

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.

  • When this.start and point are considered equal or point lands on the ray, it is considered clockwise. When point lands on the inverse of the ray, it is considered counter-clockwise.
See:
Parameters:
Name Type Description
point Rac.Point

A Point to measure the orientation to

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 Point to project onto the ray

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, null is returned.

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

A Point to point the Ray towards

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 Segment

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 Ray to calculate the intersection with

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

A Point to point the Segment towards

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.

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.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 start by

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 Angle to move start towards

distance number

The distance to move start by

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 start by

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 Ray

withAngleAdd(angle) → {Rac.Ray}

Returns a new Ray 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.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 Ray

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 Ray

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 Ray

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.