starry-math
    Preparing search index...

    Class Ray

    Represents a ray in 3D space with an origin point and direction vector. A ray extends infinitely in one direction from the origin.

    Index

    Constructors

    • Creates a new Ray instance.

      Parameters

      • Optionalorigin: Vector3 = ...

        The origin point of the ray.

      • Optionaldirection: Vector3 = ...

        The direction vector of the ray.

      Returns Ray

    Properties

    direction: Vector3

    The direction vector of the ray (typically normalized).

    origin: Vector3

    The origin point of the ray.

    Methods

    • Applies a 4x4 transformation matrix to this ray.

      Parameters

      • matrix4: IMatrix4

        The transformation matrix to apply.

      Returns this

      This ray instance for method chaining.

    • Computes a point along the ray at parameter t.

      Parameters

      • t: number

        The distance parameter along the ray.

      • target: Vector3

        The target vector to store the result.

      Returns Vector3

      The computed point along the ray.

    • Creates a new ray with the same origin and direction as this one.

      Returns Ray

      A new ray with the same properties.

    • Finds the closest point on the ray to a given point.

      Parameters

      • point: Vector3

        The point to find the closest point to.

      Returns Vector3

      The closest point on the ray.

    • Copies the origin and direction from another ray.

      Parameters

      • source: Ray

        The ray to copy from.

      Returns this

      This ray instance for method chaining.

    • Computes the squared distance from the ray to a point. More efficient than distanceToPoint as it avoids the square root operation.

      Parameters

      • point: Vector3

        The point to compute distance to.

      Returns number

      The squared distance from the ray to the point.

    • Computes the squared distance from the ray to a line segment.

      Parameters

      • v0: Vector3

        The first endpoint of the segment.

      • v1: Vector3

        The second endpoint of the segment.

      • OptionalpointOnRay: Vector3

        Optional target vector to store the closest point on the ray.

      • OptionalpointOnSegment: Vector3

        Optional target vector to store the closest point on the segment.

      Returns number

      The squared distance from the ray to the segment.

    • Computes the distance from the ray to a point.

      Parameters

      • point: Vector3

        The point to compute distance to.

      Returns number

      The distance from the ray to the point.

    • Checks if this ray is equal to another ray.

      Parameters

      • ray: Ray

        The ray to compare with.

      Returns boolean

      True if the rays are equal, false otherwise.

    • Tests if the ray intersects a box.

      Parameters

      • box: Box3

        The box to test intersection with.

      Returns Vector3 | null

      The intersection point if the ray intersects the box, null otherwise.

    • Sets the direction of the ray to point from the origin to the given point. The direction vector is automatically normalized.

      Parameters

      Returns this

      This ray instance for method chaining.

    • Moves the origin of the ray along its direction by distance t.

      Parameters

      • t: number

        The distance to move the origin.

      Returns this

      This ray instance for method chaining.

    • Sets the origin and direction of this ray.

      Parameters

      • origin: Vector3

        The new origin point.

      • direction: Vector3

        The new direction vector.

      Returns this

      This ray instance for method chaining.