mpri-graphics-project/Implicit.cpp

18 lines
659 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;
return Point(
(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));
}