Reference

std/geometry/sphere

std/geometry/src/sphere.trb

Sphere, the ball in space: the bounding volume whose overlap test is one subtraction, one dot product and one comparison, and which a rotation does not change at all.

type Sphere

type Sphere<Scalar: Real = Float>

A ball: a midpoint and a radius. The surface is inside it, exactly as a Circle's boundary is.

Examples

const ball = Sphere Vector3(0.0, 0.0, 0.0), 1.0
print "{ball.contains(Vector3(1.0, 0.0, 0.0))} {ball.contains(Vector3(1.1, 0.0, 0.0))}"

Related

field center

center: Vector3<Scalar>

The midpoint.

field radius

radius: Scalar

How far the ball reaches from its midpoint.

fn around

static fn around(box: Box<Scalar>): Sphere<Scalar>

The ball through the corners of the box.

The radius is a square root, so a scalar of limited resolution rounds it down and a corner can fall one step outside. A broad phase that must not lose a corner grows the answer by one step.

fn isEmpty

fn isEmpty(): Bool

Whether the radius is negative, in which case the ball describes no points.

fn contains

fn contains(point: Vector3<Scalar>): Bool

Whether the point is in the ball, surface included.

fn encloses

fn encloses(other: Sphere<Scalar>): Bool

Whether the other ball is inside this one, surface included.

fn intersects

fn intersects(other: Sphere<Scalar>): Bool

Whether the two balls share a point, touching included.

fn intersectsBox

fn intersectsBox(other: Box<Scalar>): Bool

Whether the ball shares a point with the box, which is a test against the nearest point of the box.

fn closestPoint

fn closestPoint(to: Vector3<Scalar>): Vector3<Scalar>

The point of the ball that is nearest to the one given, which is the point itself where it is inside.

fn distanceTo

fn distanceTo(point: Vector3<Scalar>): Scalar

The distance from the point to the nearest point of the ball. Zero where it is inside.

fn translated

fn translated(by: Vector3<Scalar>): Sphere<Scalar>

The same ball moved.

fn grown

fn grown(by: Scalar): Sphere<Scalar>

The same ball with the radius grown by that much. A negative amount shrinks it.

fn bounds

fn bounds(): Box<Scalar>

The smallest box that holds the ball.

fn combined

fn combined(other: Sphere<Scalar>): Sphere<Scalar>

The smallest ball that holds both.