Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace ray_math

Index

Functions

distancePointToRay

  • distancePointToRay(ray0: vec3, ray1: vec3, point: vec3): number
  • Computes the shortest distance of a point to a ray (closest point on ray distance).

    Parameters

    • ray0: vec3

      Start point of a ray.

    • ray1: vec3

      Far point of a ray, used to derive the ray direction.

    • point: vec3

      Point to compute the distance for.

    Returns number

    • Distance of the closest point on a ray to a point.

eyeWithPointInView

  • Computes a new eye coordinate for the camera that should have the given point within view. The eye is only modified with respect to its distance to the camera's center (on the camera look-at ray).

    Parameters

    • camera: Camera

      Camera as base constraint for the eye movement (only distance to center is changed).

    • point: vec3

      Point to adjust the camera position for.

    Returns vec3

    • Eye coordinate for the given camera that should have the given point within view.

isPointWithinNDC

  • isPointWithinNDC(viewProjection: mat4, point: vec3): boolean
  • Evaluates whether or not a given point is within the NDC-space (normalized device coordinates) after being transformed by a view projection matrix.

    Parameters

    • viewProjection: mat4

      (Model) view projection matrix to transform the point with.

    • point: vec3

      Point that is to be transformed

    Returns boolean

    True if the point should be visible (within NDC), false otherwise.

isPointWithinSquare

  • isPointWithinSquare(point: vec2, halfLength?: number): boolean
  • Evaluates whether or not a given point is within a square of a given edge length.

    Parameters

    • point: vec2

      Point to check the within-square-status for.

    • halfLength: number = 1.0

      Half of the side length of the square.

    Returns boolean

    • Whether or not the given point is within an axis aligned square at [0.0, 0.0] and edge length.

pointSquareIntersection

  • pointSquareIntersection(point: vec2, edgeLength?: number): vec2
  • Computes the intersection point of a ray starting at a given point and pointing to the center of an axis-aligned square of a given side length.

    Parameters

    • point: vec2

      Starting point used to derive a ray for intersection.

    • edgeLength: number = 1.0

      Side length of the square.

    Returns vec2

    • The intersection point of the square and the derived ray.

rayCircleIntersection

  • rayCircleIntersection(ray0: vec2, ray1: vec2, radius?: number): vec2 | undefined
  • Computes the intersection point of a given ray and a circle at [0.0, 0.0] and a given radius.

    Parameters

    • ray0: vec2

      Start point of a ray.

    • ray1: vec2

      Far point of a ray, used to derive the ray's direction.

    • radius: number = 1.0

      Radius of the circle to test for intersection with.

    Returns vec2 | undefined

    The intersection point of the given ray and a circle, undefined if no intersection exists.

rayLineIntersection

  • Computes the intersection of a ray with a line.

    Parameters

    • ray0: vec2

      Start point of a ray.

    • ray1: vec2

      Far point of a ray, used to derive the ray direction.

    • line0: vec2

      Start point of a line.

    • line1: vec2

      End point of a line.

    Returns [vec2, number] | undefined

    • If ray intersects, a 2-tuple of intersection point and t (ray0 + t + ray1) is returned.

rayPlaneIntersection

  • Computes the intersection point of a given ray and a given plane (rooted at [ 0, 0, 0 ]). t = -(dot(plane.xyz, origin) + plane.w) / dot(plane.xyz, ray); The ray intersects when (t > 0.0) && (t < tm) is true.

    Parameters

    • ray0: vec3

      Start point of a ray.

    • ray1: vec3

      Far point of a ray, used to derive the ray direction.

    • origin: vec3 = ...

      Point on a plane with origin [ 0, 0, 0 ].

    • normal: vec3 = ...

      Normal of the plane with origin [ 0, 0, 0 ].

    Returns vec3 | undefined

    • If ray intersects, the intersection point on the plane if the plane was hit.

rayPlaneIntersection_tube

  • rayPlaneIntersection_tube(ray0: vec3, ray1: vec3, radius?: number): vec3 | undefined
  • Computes the intersection point of a given ray and a given plane (origin [ 0, 0, 0 ]). The intersection point, however, is constrained to a tube of a given radius. The computation is currently limited to a tube on the plane y = 0 with origin in [0.0, 0.0, 0.0], extending towards [0.0, 1.0, 0.0].

    Parameters

    • ray0: vec3

      Start point of a ray.

    • ray1: vec3

      Far point of a ray, used to derive the ray direction.

    • radius: number = 1.0

      Constrain intersection point to be within a tube of this radius.

    Returns vec3 | undefined

    • The intersection point on the plane if the plane was hit, undefined otherwise.

raySphereIntersection

  • raySphereIntersection(ray0: vec3, ray1: vec3, origin?: vec3, radius?: number): vec3 | undefined
  • Computes the intersection point of a given ray and a given sphere. t = -(dot(plane.xyz, origin) + plane.w) / dot(plane.xyz, ray); The ray intersects when (t > 0.0) && (t < tm) is true.

    Parameters

    • ray0: vec3

      Start point of a ray.

    • ray1: vec3

      Far point of a ray, used to derive the ray direction.

    • origin: vec3 = ...

      Location of the sphere.

    • radius: number = 1.0

      Radius of the sphere.

    Returns vec3 | undefined

    • If ray intersects, the intersection point on the plane if the plane was hit.

raySquareIntersection

  • raySquareIntersection(ray0: vec2, ray1: vec2, halfLength?: number): number[]
  • Computes the intersection of a ray with an axis-aligned square at [0.0, 0.0] with side length of 2 * halfLength.

    Parameters

    • ray0: vec2

      Start point of a ray.

    • ray1: vec2

      Far point of a ray, used to derive the ray's direction.

    • halfLength: number = 1.0

    Returns number[]

    • The intersection point of the square and the ray.