20 lines
693 B
C++
20 lines
693 B
C++
#include "Implicit.hpp"
|
|
|
|
double ImplicitSurface::operator()(const Point& pt) const {
|
|
return operator()(pt.x, pt.y, pt.z);
|
|
}
|
|
|
|
Point ImplicitSurface::normal_at(const Point& pt) const {
|
|
// this is simply the gradient.
|
|
static const double d_dist = 1e-8;
|
|
|
|
Point normal(
|
|
(operator()(pt.x + d_dist, pt.y, pt.z) -
|
|
operator()(pt.x - d_dist, pt.y, pt.z)) / (2. * d_dist),
|
|
(operator()(pt.x, pt.y + d_dist, pt.z) -
|
|
operator()(pt.x, pt.y - d_dist, pt.z)) / (2. * d_dist),
|
|
(operator()(pt.x, pt.y, pt.z + d_dist) -
|
|
operator()(pt.x, pt.y, pt.z - d_dist)) / (2. * d_dist));
|
|
normal.normalize();
|
|
return normal;
|
|
}
|