29#ifndef GU_DISTANCE_POINT_TRIANGLE_H
30#define GU_DISTANCE_POINT_TRIANGLE_H
32#include "foundation/PxVec3.h"
33#include "common/PxPhysXCommonConfig.h"
43 PX_FORCE_INLINE PX_CUDA_CALLABLE PxVec3 closestPtPointTriangle2(
const PxVec3& p,
const PxVec3& a,
const PxVec3& b,
const PxVec3& c,
const PxVec3& ab,
const PxVec3& ac)
48 const PxVec3 ap = p - a;
49 const float d1 = ab.dot(ap);
50 const float d2 = ac.dot(ap);
51 if(d1<=0.0f && d2<=0.0f)
55 const PxVec3 bp = p - b;
56 const float d3 = ab.dot(bp);
57 const float d4 = ac.dot(bp);
58 if(d3>=0.0f && d4<=d3)
62 const float vc = d1*d4 - d3*d2;
63 if(vc<=0.0f && d1>=0.0f && d3<=0.0f)
65 const float v = d1 / (d1 - d3);
70 const PxVec3 cp = p - c;
71 const float d5 = ab.dot(cp);
72 const float d6 = ac.dot(cp);
73 if(d6>=0.0f && d5<=d6)
77 const float vb = d5*d2 - d1*d6;
78 if(vb<=0.0f && d2>=0.0f && d6<=0.0f)
80 const float w = d2 / (d2 - d6);
85 const float va = d3*d6 - d5*d4;
86 if(va<=0.0f && (d4-d3)>=0.0f && (d5-d6)>=0.0f)
88 const float w = (d4-d3) / ((d4 - d3) + (d5-d6));
93 const float denom = 1.0f / (va + vb + vc);
94 const float v = vb * denom;
95 const float w = vc * denom;
96 return a + ab*v + ac*w;
99 PX_PHYSX_COMMON_API PxVec3 closestPtPointTriangle(
const PxVec3& p,
const PxVec3& a,
const PxVec3& b,
const PxVec3& c,
float& s,
float& t);
101 PX_FORCE_INLINE PxReal distancePointTriangleSquared(
const PxVec3& point,
102 const PxVec3& triangleOrigin,
103 const PxVec3& triangleEdge0,
104 const PxVec3& triangleEdge1,
108 const PxVec3 pt0 = triangleEdge0 + triangleOrigin;
109 const PxVec3 pt1 = triangleEdge1 + triangleOrigin;
111 const PxVec3 cp = closestPtPointTriangle(point, triangleOrigin, pt0, pt1, s, t);
116 return (cp - point).magnitudeSquared();
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39