【问题标题】:How can I check collision between a triangle - circle and triangle rectangle? (including rotation)如何检查三角形 - 圆形和三角形矩形之间的碰撞? (包括轮换)
【发布时间】:2013-01-28 07:10:00
【问题描述】:

我需要检查一些形状是否在 2D 世界中发生碰撞。

为了检查圆形和矩形之间的碰撞,我发现了这个: Collision Detection with Rotated Rectangles

但现在我需要在这段代码中添加另一个形状(三角形),三角形也可以旋转。

我该怎么做?

【问题讨论】:

  • 使用库。 Geos,Shapely,Jts
  • 但是一般来说,矩形和三角形都是多边形。您真正需要知道的只是如何使线和线相交,以及如何使线和圆相交。

标签: math 2d collision shapes intersect


【解决方案1】:

这个 JSTS 示例(在 javascript 中)展示了如何使两个多边形相交。

https://github.com/bjornharrtell/jsts/blob/master/examples/overlay.html

为了修改示例使其中一个变成圆形,使用这个sn-p:

// this returns a JSTS polygon circle approximation with provided center and radius
function pointJSTS(center,radius){
  var point = new jsts.geom.Point(center);
  return point.buffer(radius);
}
// ....
// insert this into the example above at line 17
b = pointJSTS({x:10,y:20}, 40);

进一步修改示例以使第一个多边形变成三角形是微不足道的。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-27
  • 1970-01-01
相关资源
最近更新 更多