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

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

问题描述

在给定二维坐标平面上的顶点的情况下,如何以编程方式检测两个三角形是否相互接触?这包括接触点或边缘,以及一个三角形是否完全在另一个三角形内.

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.

推荐答案

使用Line Line相交

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天全站免登陆