# 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)

Source:
##### Parameters:
Name Type Description
`A` Object

The origin of the Ray

`B` Object

The destination of the Ray

### Members

#### angle :number

Source:

The normalized angle of the ray in radians on the range (-PI, PI)

• number

#### distance :number

Source:

The distance of the ray

• number

#### normAngle :number

Source:

Return the value of the angle normalized to the range (0, 2*PI) This is useful for testing whether an angle falls between two others

• number

#### slope :number

Source:

The slope of the ray, dy over dx

• number

### Methods

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

Source:

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

`distance` number

The distance of the ray in pixels

##### Returns:

The constructed Ray instance

Type
Ray

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

Source:

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

#### intersectSegment(coords) → {Object|false}

Source:

Find the point I[x,y] and distance t* on ray R(t) which intersects another ray http://paulbourke.net/geometry/pointlineplane/

##### Parameters:
Name Type Description
`coords` Array.<number>

An array of coordinates [x0, y0, x1, y1] which defines a line segment to test

##### Returns:

The point of collision [x,y] the position of that collision point along the Ray (t0) an the tested segment (t1). Returns false if no collision occurs.

Type
Object | false

#### project(t) → {Object}

Source:

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

#### shiftAngle(offset, distanceopt) → {Ray}

Source:

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