Implicit surfaces: add normal vector
This commit is contained in:
parent
ebf3f7a267
commit
2789acb5c5
2 changed files with 16 additions and 0 deletions
13
Implicit.cpp
13
Implicit.cpp
|
@ -3,3 +3,16 @@
|
||||||
double ImplicitSurface::operator()(const Point& pt) const {
|
double ImplicitSurface::operator()(const Point& pt) const {
|
||||||
return operator()(pt.x, pt.y, pt.z);
|
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));
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ class ImplicitSurface {
|
||||||
virtual double operator() (double x, double y, double z) const = 0;
|
virtual double operator() (double x, double y, double z) const = 0;
|
||||||
double operator()(const Point& pt) const;
|
double operator()(const Point& pt) const;
|
||||||
Point getCenter() const { return center;}
|
Point getCenter() const { return center;}
|
||||||
|
|
||||||
|
/// Compute the normal vector to the isosurface at `pt`
|
||||||
|
Point normal_at(const Point& pt) const;
|
||||||
protected:
|
protected:
|
||||||
Point center;
|
Point center;
|
||||||
ImplicitSurface(Point _center) : center(_center) {}
|
ImplicitSurface(Point _center) : center(_center) {}
|
||||||
|
|
Loading…
Reference in a new issue