Skip to content

Sphere3

Overview

A sphere in 3 dimensions (NOT a 3-sphere).

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

Class Sphere3

import { Sphere3 } from 'scenerystack/dot';

Constructor

new Sphere3( center, radius )

Instance Methods

intersect( ray, epsilon )

Determines if a ray (a half-line) intersects this sphere. A successful intersection returns the result the closest intersection in the form { distance, hitPoint, normal, fromOutside }, distance: {number} distance to the intersection point hitPoint: {Vector3} the intersection point normal: {Vector3} the normal vector on the sphere at the point of intersection. (the normal vector points outwards the sphere by convention) fromOutside: {boolean} is the ray half-line intersecting the sphere from the outside of a sphere or from the inside.

Returns null if the ray misses the sphere

@public @param {Ray3} ray - The ray to intersect with the sphere @param {number} epsilon - A small varying-point value to be used to handle intersections tangent to the sphere @returns {{ distance: number, hitPoint: Vector3, normal, fromOutside: boolean }| null}

intersections( ray, epsilon )

Returns the intersections of a ray with a sphere. There will be 0 or 2 intersections, with the "proper" intersection first, if applicable (closest in front of the ray). Note that this method makes the implicit assumptions that the ray's origin does not lie inside the sphere.

@public @param {Ray3} ray - The ray to intersect with the sphere @param {number} epsilon - A small varying-point value to be used to handle intersections tangent to the sphere @returns {Array.<{distance:number, hitPoint:Vector3, normal:Vector3, fromOutside:boolean }>| null} - An array of intersection results like { distance, hitPoint, normal, fromOutside }.

Source Code

See the source for Sphere3.js in the dot repository.