二维空间中三角形碰撞的检测 [英] Detection of Triangle Collision in 2D Space

查看:120
本文介绍了二维空间中三角形碰撞的检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检测两个三角形是否相互接触,并在2D坐标平面上给出它们的顶点?这包括接触点或边缘,以及如果一个三角形完全位于另一个三角形内部。使用线条交集 使用线条交集 / p>

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

 函数SameSide(p1,p2,a,b)
cp1 = CrossProduct( ba,p1-a)
cp2 = CrossProduct(ba,p2-a)
如果DotProduct(cp1, cp2)> = 0然后返回true
else返回false

函数PointInTriangle(p,a,b,c)
如果SameSide(p,a,b,c)和SameSide(p,b,a,c)
和SameSide(p,c,a,b)然后返回true
else返回false

或者看看这个链接并向下滚动



http://compsci.ca/v3/viewtopic.php?t=6034


How can I programmatically detect whether or not two triangles touch each other, given their vertices on a 2D coordinate plane? This includes touching points or edges, as well as if one triangle is completely inside the other one.

解决方案

Use Line Line intersection

https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-line-intersection-and-its-applications/#line_line_intersection

Also consider the possibility that some vertex might be touching one of the sides of the other triangle.

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

Or look at this link and scroll down

http://compsci.ca/v3/viewtopic.php?t=6034

这篇关于二维空间中三角形碰撞的检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆