如果你有2个点,(X1,Y1)和(X2,Y2),从而重新present矩形的两个相对的角,并且其他2个点,(X3,Y3)和(X4,Y4) ,从而重新present线段的端点2,你怎么能检查线段相交的矩形?
If you have 2 points, (x1, y1) and (x2, y2), which represent two opposite corners of a rectangle, and 2 other points, (x3,y3) and (x4,y4), which represent 2 endpoints of a line segment, how can you check if the line segment intersects the rectangle?
(线段只是给定的端点之间包含的段,它不是由这二个点所限定的无限长行。)
(The line segment is just the segment contained between the given endpoints. It is not an infinite length line defined by those two points.)
推荐答案一个很简单的办法是使用a标准算法检查两条线段相交是否来检查是否线段相交的任何4条线段构成盒子的角落。它的计算非常有效的检查,如果两条线段相交,所以我希望这可以运行速度非常快。
One very simple option would be to use a standard algorithm for checking whether two line segments intersect to check whether the line segments intersects any of the four line segments that make up the corners of the box. It's computationally very efficient to check if two line segments intersect, so I would expect that this could run very quickly.
希望这有助于!
更多推荐
如何检查是否线段相交的矩形?
发布评论