如何找到相交矩形的相交矩形(点) [英] How to find intersection rectangle(points) of instersecting rectangles

查看:81
本文介绍了如何找到相交矩形的相交矩形(点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个相交的矩形[(x1,y1)(x2,y2)][(x3,y3)(x4,y4)] 由两个顶点描述.如何找到一个矩形,它是它们的内切效果(在这些矩形相交的地方得到 2 个点).

If I have two instersecting rectangles[(x1,y1)(x2,y2)][(x3,y3)(x4,y4)] described by two verticles. How to find a rectangle which is effect of their intasection(get 2 points where these rectangles intersect).

编程语言无关紧要.可能是伪代码.

Prgramming language does not matter. May be pseudo code.

PS:矩形平行于 OXY.

PS: Rectangles are parallel to the OXY.

推荐答案

您可以使用 Rectangle.intersection:

Rectangle intersection = rectangle1.intersection(rectangle2);

生成的矩形的 2 个顶点将是交点.您可以使用 Rectangle.contains 来确定公共点.

2 of the vertices of the resulting rectangle will be the intersection points. You can use Rectangle.contains to determine the common points.

参见:矩形相交源

这篇关于如何找到相交矩形的相交矩形(点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆