如何找到相交矩形的相交矩形(点)
问题描述:
如果我有两个相交的矩形[(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.
参见:矩形相交源