33 #ifndef ISOEX_IMPLICITSPHERE_HH
34 #define ISOEX_IMPLICITSPHERE_HH
39 #include "Implicit.hh"
40 #include <IsoEx/Config/IsoExDefines.hh>
55 template<
class Vec3 >
60 typedef typename Vec3::value_type real;
69 sqr_radius_(_radius*_radius)
84 return (center_ - _point).sqrnorm() <= sqr_radius_;
89 return (center_ - _point).norm() - radius_;
96 real& _distance)
const
98 Vec3 orig(_p0), dir(_p1-_p0);
100 double a = dir.sqrnorm();
101 double b = 2.0*(dir | (orig - center_));
102 double c = (orig - center_).sqrnorm() - radius_*radius_;
103 double d = b*b - 4.0*a*c;
109 double t1 = (-b-d) / (2.0*a);
110 double t2 = (-b+d) / (2.0*a);
112 if (t1 >= 0.0 && t1 < t) t = t1;
113 if (t2 >= 0.0 && t2 < t) t = t2;
117 _point = orig + dir*t;
118 _normal = (_point - center_) / radius_;
119 _distance = ((dir | _normal) < 0.0) ? dir.norm()*t : -dir.norm()*t;
141 #endif // ISOEX_IMPLICITSPHERE_HH defined
bool directed_distance(const Vec3 &_p0, const Vec3 &_p1, Vec3 &_point, Vec3 &_normal, real &_distance) const
Definition: ImplicitSphere.hh:92
ImplicitSphere(const Vec3 &_center, real _radius)
Constructor: given sphere center and radius.
Definition: ImplicitSphere.hh:66
bool is_inside(const Vec3 &_point) const
Definition: ImplicitSphere.hh:82
Definition: ImplicitSphere.hh:56
~ImplicitSphere()
Empty destructor.
Definition: ImplicitSphere.hh:73
real scalar_distance(const Vec3 &_point) const
Definition: ImplicitSphere.hh:87
Definition: Implicit.hh:57
A type for volume images, or 3D textures.