mpri-graphics-project/Implicit.cpp

19 lines
659 B
C++
Raw Normal View History

#include "Implicit.hpp"
double ImplicitSurface::operator()(const Point& pt) const {
return operator()(pt.x, pt.y, pt.z);
}
2018-02-13 13:22:41 +01:00
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));
}