|
- bool pointInTriangle(const Eigen::Vector3f& query采用point,
- const Eigen::Vector3f& triangle采用vertex采用0,
- const Eigen::Vector3f& triangle采用vertex采用1,
- const Eigen::Vector3f& triangle采用vertex采用2)
- {
- // u=P2−P1
- Eigen::Vector3f u = triangle采用vertex采用1 - triangle采用vertex采用0;
- // v=P3−P1
- Eigen::Vector3f v = triangle采用vertex采用2 - triangle采用vertex采用0;
- // n=u×v
- Eigen::Vector3f n = u.cross(v);
- // w=P−P1
- Eigen::Vector3f w = query采用point - triangle采用vertex采用0;
- // Barycentric coordinates of the projection P′of P onto T:
- // γ=[(u×w)⋅n]/n²
- float gamma = u.cross(w).dot(n) / n.dot(n);
- // β=[(w×v)⋅n]/n²
- float beta = w.cross(v).dot(n) / n.dot(n);
- float alpha = 1 - gamma - beta;
- // The point P′ lies inside T if:
- return ((0 <= alpha) && (alpha <= 1) &&
- (0 <= beta) && (beta <= 1) &&
- (0 <= gamma) && (gamma <= 1));
- }
复制代码 |
|