# Sphere3¶

```#include <Imath/ImathSphere.h>
```

The `Sphere3` class template represents a sphere in 3D space, with predefined typedefs for lines of type `float` and `double`.

Example:

```#include <Imath/ImathSphere.h>
#include <cassert>

void
sphere3_example ()
{
Imath::V3f      center (1.0f, 1.0f, 1.0f);

assert (s.center == center);

Imath::Line3f line (
Imath::V3f (0.0f, 0.0f, 0.0f), Imath::V3f (1.0f, 1.0f, 1.0f));

Imath::V3f v;
assert (s.intersect (line, v));

assert (
v.equalWithAbsError (Imath::V3f (2.1547f, 2.1547f, 2.1547f), 1e-6f));
}
```
typedef Sphere3<float> Imath::Sphere3f

Sphere of type float.

template<class T>
class Sphere3

A 3D sphere.

Vec3<T> center

Center.

Constructors

inline constexpr Sphere3()

Default is center at (0,0,0) and radius of 0.

inline constexpr Sphere3(const Vec3<T> &c, T r)

Initialize to a given center and radius.

Manipulation

inline void circumscribe(const Box<Vec3<T>> &box)

Set the center and radius of the sphere so that it tightly encloses Box b.

Utility Methods

constexpr bool intersect(const Line3<T> &l, Vec3<T> &intersection) const

If the sphere and line `l` intersect, then compute the smallest `t` with `t>=0` so that `l(t)` is a point on the sphere.

Parameters:
• l[in] The line

• intersection[out] The point of intersection

Returns:

True if the sphere and line intersect, false if they do not.

constexpr bool intersectT(const Line3<T> &l, T &t) const

If the sphere and line `l` intersect, then compute the smallest `t` with `t>=0` so that `l(t)` is a point on the sphere.

Parameters:
• l[in] The line

• t[out] The parameter of the line at the intersection point

Returns:

True if the sphere and line intersect, false if they do not.