geom/plane: add distance2
for plane/point
This commit is contained in:
parent
92ba5469c4
commit
1324ae2b4a
@ -75,16 +75,31 @@ namespace util::geom {
|
||||
/// calculates the distance from a plane to a point.
|
||||
///
|
||||
/// positive distances are in front of the plane, negative is behind;
|
||||
///
|
||||
/// NOTE: `distance2` is _not_ the squared distance. It is the
|
||||
/// unnormalised distance. It needs to be divided by the norm of the
|
||||
/// plane normal.
|
||||
template <size_t S, typename T>
|
||||
T
|
||||
distance2 (plane<S,T> p, point<S,T> q)
|
||||
{
|
||||
return dot (p.coefficients, q.template redim<S+1> (1));
|
||||
}
|
||||
|
||||
|
||||
template <size_t S, typename T>
|
||||
T
|
||||
distance2 (point<S,T> p, plane<S,T> q)
|
||||
{
|
||||
return -distance2 (q, p);
|
||||
}
|
||||
|
||||
|
||||
template <size_t S, typename T>
|
||||
T
|
||||
distance (plane<S,T> p, point<S,T> q)
|
||||
{
|
||||
auto d = dot (
|
||||
p.coefficients,
|
||||
q.template redim<S+1> (1)
|
||||
);
|
||||
|
||||
return d / norm (normal (p));
|
||||
return distance2 (p, q) / norm (normal (p));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user