Skip to content

sphereRayIntersection

Under Construction

This documentation is auto-generated, and is a work in progress. Please see the source code at https://github.com/phetsims/dot/blob/main/js/util/sphereRayIntersection.ts for the most up-to-date information.

Overview

Ray-sphere intersection, returning information about the closest intersection. Assumes the sphere is centered at the origin (for ease of computation), transform the ray to compensate if needed.

If there is no intersection, null is returned. Otherwise an object will be returned like: <pre class="brush: js"> { distance: {number}, // distance from the ray position to the intersection hitPoint: {Vector3}, // location of the intersection normal: {Vector3}, // the normal of the sphere's surface at the intersection fromOutside: {boolean}, // whether the ray intersected the sphere from outside the sphere first } </pre>

@author Jonathan Olson <jonathan.olson@colorado.edu>

Type SphereRayIntersectionResult

import type { SphereRayIntersectionResult } from 'scenerystack/dot';
  • distance: number
  • hitPoint: Vector3
  • normal: Vector3
  • fromOutside: boolean

Source Code

See the source for sphereRayIntersection.ts in the dot repository.