无轴对齐矩形交集 [英] Non axis-aligned rectangle intersection

查看:123
本文介绍了无轴对齐矩形交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个算法,将计算交会2矩形,这不一定是轴对齐之间,并返回得到的交集。

I'm trying to find an algorithm that will compute the intersection between 2 rectangles, which are not necessarily axis-aligned, and return the resulting intersection.

<一个href="http://stackoverflow.com/questions/115426/algorithm-to-detect-intersection-of-two-rectangles">This问题介绍找到一个交集是否存在。我想有所得的路口形状,如果存在的话。

This question describes finding whether an intersection exists. I'd like to have the resulting shape of the intersection, if it exists.

我的算法的应用将使用一个轴对齐矩形和一个是不一定轴对齐,而是一般的算法将是preferable

My application of the algorithm will use one axis-aligned rectangle and one that is not necessarily axis-aligned, but a general algorithm would be preferable.

谢谢!

推荐答案

一算法寻找交集任何两个凸多边形包括首先发现周围所有的顶点的凸包。凸包如下为准多边形轮廓的最外层的的;你正在寻找的形状遵循大纲为准多边形的最里面的的,所以按照凸包没有遵循哪一个。 这里是prettier图片相同的算法。

One algorithm for finding the intersection of any two convex polygons involves first finding the convex hull around all the vertices. The convex hull follows the outline of whichever polygon is outermost; the shape you're seeking follows the outline of whichever polygon is innermost, so follow whichever one the convex hull isn't following. Here is a prettier picture of the same algorithm.

这种极其简单的维基页面提到其他两个算法。一个人,你打破了多边形成梯形。另一种是左右两个多边形逆时针行走在锁步的一个非常聪明的方式。我想我喜欢这一个最好的,但由于维基说,这是相当难来形容。

This extremely brief wiki page mentions two other algorithms. One has you breaking the polygons into trapezoids. The other is a very clever way of walking around both polygons counterclockwise in lock step. I think I like this one best, but as the wiki says, it's rather hard to describe.

这篇关于无轴对齐矩形交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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