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>

void
sphere3_example()
{
    Imath::V3f center (1.0f, 1.0f, 1.0f); 
    float radius = 2.0f;
    Imath::Sphere3f s (center, radius);

    assert (s.center == center);
    assert (s.radius == radius);
    
    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 Imath::Sphere3

A 3D sphere.

Direct access to member fields

Vec3<T> center

Center.

T radius

Radius.

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.