13#ifndef NANOVDB_MATH_PROXIMITY_H_HAS_BEEN_INCLUDED
14#define NANOVDB_MATH_PROXIMITY_H_HAS_BEEN_INCLUDED
28template<
typename Vec3T>
32 const Vec3T seg = v1 - v0;
33 const Vec3T w = p - v0;
35 const auto c1 = seg.dot(w);
36 if (c1 <= 0)
return v0;
38 const auto c2 = seg.dot(seg);
39 if (c2 <= c1)
return v1;
41 return v0 + (c1 / c2) * seg;
55template<
typename Vec3T>
62 typename Vec3T::ValueType &t0,
63 typename Vec3T::ValueType &t1)
65 using RealT =
typename Vec3T::ValueType;
67 const Vec3T ab = v1 - v0;
68 const Vec3T ac = v2 - v0;
69 const Vec3T ap = p - v0;
72 const RealT d1 = ab.dot(ap);
73 const RealT d2 = ac.dot(ap);
74 if (d1 <= RealT(0) && d2 <= RealT(0)) {
81 const Vec3T bp = p - v1;
82 const RealT d3 = ab.dot(bp);
83 const RealT d4 = ac.dot(bp);
84 if (d3 >= RealT(0) && d4 <= d3) {
91 const RealT vc = d1 * d4 - d3 * d2;
92 if (vc <= RealT(0) && d1 >= RealT(0) && d3 <= RealT(0)) {
99 const Vec3T cp = p - v2;
100 const RealT d5 = ab.dot(cp);
101 const RealT d6 = ac.dot(cp);
102 if (d6 >= RealT(0) && d5 <= d6) {
109 const RealT vb = d5 * d2 - d1 * d6;
110 if (vb <= RealT(0) && d2 >= RealT(0) && d6 <= RealT(0)) {
117 const RealT va = d3 * d6 - d5 * d4;
118 if (va <= RealT(0) && (d4 - d3) >= RealT(0) && (d5 - d6) >= RealT(0)) {
119 t1 = (d4 - d3) / ((d4 - d3) + (d5 - d6));
121 return v1 + t1 * (v2 - v1);
125 const RealT denom = RealT(1) / (va + vb + vc);
128 return v0 + t0 * ab + t1 * ac;
133template<
typename Vec3T>
141 typename Vec3T::ValueType t0, t1;
143 return (p - closest).lengthSqr();
#define __hostdev__
Definition SampleFromVoxels.h:29
Definition DitherLUT.h:19
__hostdev__ Vec3T closestPointOnTriangleToPoint(const Vec3T &v0, const Vec3T &v1, const Vec3T &v2, const Vec3T &p, typename Vec3T::ValueType &t0, typename Vec3T::ValueType &t1)
Returns the closest point on triangle [v0,v1,v2] to p, and (via t0, t1) the barycentric coordinates o...
Definition Proximity.h:57
__hostdev__ Vec3T closestPointOnSegmentToPoint(const Vec3T &v0, const Vec3T &v1, const Vec3T &p)
Returns the closest point on the line segment [v0,v1] to p.
Definition Proximity.h:30
__hostdev__ Vec3T::ValueType pointToTriangleDistSqr(const Vec3T &v0, const Vec3T &v1, const Vec3T &v2, const Vec3T &p)
Returns the squared distance from p to the closest point on triangle [v0,v1,v2].
Definition Proximity.h:135
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:31
Math functions and classes.