mpri-graphics-project/Implicit.cpp

21 lines
693 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;
2018-02-13 16:14:28 +01:00
Point normal(
2018-02-13 13:22:41 +01:00
(operator()(pt.x + d_dist, pt.y, pt.z) -
2018-02-13 16:14:28 +01:00
operator()(pt.x - d_dist, pt.y, pt.z)) / (2. * d_dist),
2018-02-13 13:22:41 +01:00
(operator()(pt.x, pt.y + d_dist, pt.z) -
2018-02-13 16:14:28 +01:00
operator()(pt.x, pt.y - d_dist, pt.z)) / (2. * d_dist),
2018-02-13 13:22:41 +01:00
(operator()(pt.x, pt.y, pt.z + d_dist) -
2018-02-13 16:14:28 +01:00
operator()(pt.x, pt.y, pt.z - d_dist)) / (2. * d_dist));
normal.normalize();
return normal;
2018-02-13 13:22:41 +01:00
}