最近在看recast&detour源码的时候有遇到许多数学上的算法问题,特此记录,以便以后查看。
重心坐标系介绍
三角形重心坐标推导

源码
使用上面推导的公式计算系数是否大于等于0.
bool dtClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h) { float v0[3], v1[3], v2[3]; dtVsub(v0, c,a); dtVsub(v1, b,a); dtVsub(v2, p,a); const float dot00 = dtVdot2D(v0, v0); const float dot01 = dtVdot2D(v0, v1); const float dot02 = dtVdot2D(v0, v2); const float dot11 = dtVdot2D(v1, v1); const float dot12 = dtVdot2D(v1, v2); // Compute barycentric coordinates const float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01); const float u = (dot11 * dot02 - dot01 * dot12) * invDenom; const float v = (dot00 * dot12 - dot01 * dot02) * invDenom; // The (sloppy) epsilon is needed to allow to get height of points which // are interpolated along the edges of the triangles. static const float EPS = 1e-4f; // If point lies inside the triangle, return interpolated ycoord. if (u >= -EPS && v >= -EPS && (u+v) <= 1+EPS) { h = a[1] + v0[1]*u + v1[1]*v; return true; } return false; }
讯享网
参考
https://en.wikipedia.org/wiki/Barycentric_coordinate_system

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/18590.html