10 #ifndef INCLUDED_ATOMSMATHSPHERE_H
11 #define INCLUDED_ATOMSMATHSPHERE_H
13 #include <AtomsMath/ImathBox.h>
14 #include <AtomsMath/ImathLine.h>
15 #include <AtomsMath/ImathNamespace.h>
16 #include <AtomsMath/ImathVec.h>
18 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
69 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
bool
79 ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14
bool intersectT (
const Line3<T>& l, T& t)
const;
98 center = T (0.5) * (box.min + box.max);
99 radius = (box.max - center).length();
103 ATOMSMATH_CONSTEXPR14
bool
106 bool doesIntersect =
true;
109 T B = T (2.0) * (line.
dir ^ v);
110 T C = (v ^ v) - (radius * radius);
115 T discr = B * B - T (4.0) * C;
121 doesIntersect =
false;
127 T sqroot = std::sqrt (discr);
128 t = (-B - sqroot) * T (0.5);
134 t = (-B + sqroot) * T (0.5);
138 doesIntersect =
false;
141 return doesIntersect;
145 ATOMSMATH_CONSTEXPR14
bool
150 if (intersectT (line, t))
152 intersection = line (t);
161 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImathBox.h:36
Definition: ImathLine.h:25
Vec3< T > pos
A point on the line.
Definition: ImathLine.h:32
Vec3< T > dir
The direction of the line.
Definition: ImathLine.h:35
Definition: ImathSphere.h:25
constexpr ATOMSMATH_HOSTDEVICE Sphere3()
Default is center at (0,0,0) and radius of 0.
Definition: ImathSphere.h:43
ATOMSMATH_HOSTDEVICE void circumscribe(const Box< Vec3< T >> &box)
Definition: ImathSphere.h:96
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool intersectT(const Line3< T > &l, T &t) const
Definition: ImathSphere.h:104
constexpr ATOMSMATH_HOSTDEVICE Sphere3(const Vec3< T > &c, T r)
Initialize to a given center and radius.
Definition: ImathSphere.h:46
Vec3< T > center
Center.
Definition: ImathSphere.h:32
ATOMSMATH_HOSTDEVICE ATOMSMATH_CONSTEXPR14 bool intersect(const Line3< T > &l, Vec3< T > &intersection) const
Definition: ImathSphere.h:146
T radius
Radius.
Definition: ImathSphere.h:35
Definition: ImathVec.h:260