gpt4 book ai didi

math - 二维空间三角形碰撞检测

转载 作者:行者123 更新时间:2023-12-04 07:29:41 27 4
gpt4 key购买 nike

考虑到两个三角形在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com