Ray

Ray

A ray for the purposes of computing sight and collision Given points A[x,y] and B[x,y]

Slope-Intercept form: y = a + bx y = A.y + ((B.y - A.Y) / (B.x - A.x))x

Parametric form: R(t) = (1-t)A + tB

Constructor

new Ray(A, B)

Parameters:
Name Type Description
A Point

The origin of the Ray

B Point

The destination of the Ray

Members

A :Point

The origin point, {x, y}

Type:

angle :number

The normalized angle of the ray in radians on the range (-PI, PI). The angle is computed lazily (only if required) and cached.

Type:
  • number

B :Point

The destination point, {x, y}

Type:

bounds :NormalizedRectangle

A bounding rectangle that encompasses the Ray

Type:

distance :number

The distance (length) of the Ray in pixels. The distance is computed lazily (only if required) and cached.

Type:
  • number

dx :number

The horizontal distance of the ray, x1 - x0

Type:
  • number

dy :number

The vertical distance of the ray, y1 - y0

Type:
  • number

slope :number

The slope of the ray, dy over dx

Type:
  • number

x0 :number

The origin x-coordinate

Type:
  • number

y0 :number

The origin y-coordinate

Type:
  • number

Methods

(static) fromAngle(x, y, radians, distance) → {Ray}

A factory method to construct a Ray from an origin point, an angle, and a distance

Parameters:
Name Type Description
x number

The origin x-coordinate

y number

The origin y-coordinate

radians number

The ray angle in radians

distance number

The distance of the ray in pixels

Returns:

The constructed Ray instance

Type
Ray

(static) fromArrays(A, B) → {Ray}

A factory method to construct a Ray from points in array format.

Parameters:
Name Type Description
A Array.<number>

The origin point [x,y]

B Array.<number>

The destination point [x,y]

Returns:

The constructed Ray instance

Type
Ray

(static) towardsPoint(origin, point, distance) → {Ray}

Create a Ray by projecting a certain distance towards a known point.

Parameters:
Name Type Description
origin Point

The origin of the Ray

point Point

The point towards which to project

distance number

The distance of projection

Returns:
Type
Ray

(static) towardsPointSquared(origin, point, distance2) → {Ray}

Create a Ray by projecting a certain squared-distance towards a known point.

Parameters:
Name Type Description
origin Point

The origin of the Ray

point Point

The point towards which to project

distance2 number

The squared distance of projection

Returns:
Type
Ray

intersectSegment()

See:
  • foundry.utils.lineLineIntersection

Find the point I[x,y] and distance t* on ray R(t) which intersects another ray

project(t) → {Object}

Project the Array by some proportion of it's initial distance. Return the coordinates of that point along the path.

Parameters:
Name Type Description
t number

The distance along the Ray

Returns:

The coordinates of the projected point

Type
Object

reverse() → {Ray}

Reverse the direction of the Ray, returning a second Ray

Returns:
Type
Ray

shiftAngle(offset, distanceopt) → {Ray}

Create a new ray which uses the same origin point, but a slightly offset angle and distance

Parameters:
Name Type Attributes Description
offset number

An offset in radians which modifies the angle of the original Ray

distance number <optional>

A distance the new ray should project, otherwise uses the same distance.

Returns:

A new Ray with an offset angle

Type
Ray