Options
All
  • Public
  • Public/Protected
  • All
Menu

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

param A

The origin of the Ray

param B

The destination of the Ray

Hierarchy

  • Ray

Index

Constructors

  • new Ray(A: any, B: any): Ray
  • Parameters

    • A: any
    • B: any

    Returns Ray

Properties

A: Point

The origin point, {x, y}

B: Point

The destination point, {x, y}

y0: number

The origin y-coordinate

x0: number

The origin x-coordinate

dx: number

The horizontal distance of the ray, x1 - x0

dy: number

The vertical distance of the ray, y1 - y0

slope: number

The slope of the ray, dy over dx

_angle: number = undefined

The cached angle, computed lazily in Ray#angle

_distance: number = undefined

The cached distance, computed lazily in Ray#distance

Accessors

  • get angle(): number
  • set angle(value: number): void
  • The normalized angle of the ray in radians on the range (-PI, PI). The angle is computed lazily (only if required) and cached.

    Returns number

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

    Parameters

    • value: number

    Returns void

  • A normalized bounding rectangle that encompasses the Ray

    Returns Rectangle

  • get distance(): number
  • set distance(value: number): void
  • The distance (length) of the Ray in pixels. The distance is computed lazily (only if required) and cached.

    Returns number

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

    Parameters

    • value: number

    Returns void

Methods

  • project(t: number): any
  • Project the Array by some proportion of it's initial distance. Return the coordinates of that point along the path.

    Parameters

    • t: number

      The distance along the Ray

    Returns any

    The coordinates of the projected point

  • Reverse the direction of the Ray, returning a second Ray

    Returns Ray

  • shiftAngle(offset: number, distance: number): Ray
  • Create a new ray which uses the same origin point, but a slightly offset angle and distance

    Parameters

    • offset: number

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

    • distance: number

    Returns Ray

    A new Ray with an offset angle

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

    see

    foundry.utils.lineLineIntersection

    Parameters

    • coords: any

    Returns LineIntersection

  • fromAngle(x: number, y: number, radians: number, distance: number): Ray
  • A factory method to construct a Ray from an origin point, an angle, and a distance

    Parameters

    • 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 Ray

    The constructed Ray instance

  • fromArrays(A: number[], B: number[]): Ray
  • A factory method to construct a Ray from points in array format.

    Parameters

    • A: number[]

      The origin point [x,y]

    • B: number[]

      The destination point [x,y]

    Returns Ray

    The constructed Ray instance

  • towardsPoint(origin: Point, point: Point, distance: number): Ray
  • Create a Ray by projecting a certain distance towards a known point.

    Parameters

    • origin: Point

      The origin of the Ray

    • point: Point

      The point towards which to project

    • distance: number

      The distance of projection

    Returns Ray

  • towardsPointSquared(origin: Point, point: Point, distance2: number): Ray
  • Create a Ray by projecting a certain squared-distance towards a known point.

    Parameters

    • origin: Point

      The origin of the Ray

    • point: Point

      The point towards which to project

    • distance2: number

      The squared distance of projection

    Returns Ray