考虑到两个三角形在 2D 坐标平面上的顶点,如何以编程方式检测它们是否相互接触?这包括接触点或边缘,以及一个三角形是否完全在另一个三角形内。
最佳答案
使用线线交点
https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-line-intersection-and-its-applications/#line_line_intersection
还要考虑某些顶点可能接触另一个三角形的一侧的可能性。
http://www.blackpawn.com/texts/pointinpoly/default.html
function SameSide(p1,p2, a,b)
cp1 = CrossProduct(b-a, p1-a)
cp2 = CrossProduct(b-a, p2-a)
if DotProduct(cp1, cp2) >= 0 then return true
else return false
function PointInTriangle(p, a,b,c)
if SameSide(p,a, b,c) and SameSide(p,b, a,c)
and SameSide(p,c, a,b) then return true
else return false
或查看此链接并向下滚动
http://compsci.ca/v3/viewtopic.php?t=6034
关于math - 二维空间三角形碰撞检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2778240/