如何检查是否线段相交的矩形?

编程入门 行业动态 更新时间:2024-10-27 14:19:37
本文介绍了如何检查是否线段相交的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果你有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.

希望这有助于!

更多推荐

如何检查是否线段相交的矩形?

本文发布于:2023-11-30 00:25:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648110.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线段   矩形

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!