简体   繁体   English

查找边缘是否位于一组不相交的矩形内

[英]Finding if an edge lies within a set of disjoint rectangles

I'm using a triangulation library to compute the Constrained Delaunay Triangulation of a set of rectangles within some large boundary. 我正在使用一个三角剖分库来计算一些大边界内的一组矩形的约束Delaunay三角剖分。 The algorithm returns all the edges, but also adds edges inside of the rectangles that define the constraints. 该算法返回所有边缘,但还会在定义约束的矩形内部添加边缘。 I want to be able to find if an edge lies inside of a rectangle in O(1) time. 我希望能够找到边缘是否在O(1)时间位于矩形内。

Here's a more general description of the problem I want to solve. 这是我要解决的问题的更一般的描述。 Given a set of nonoverlapping rectangles (the borders of the rectangles may touch) and an edge e with endpoints (x1,y1) and (x2, y2), find in O(1) time if e lies within any of the rectangles (including the border). 给定一组不重叠的矩形(矩形的边界可能会接触)以及端点为e(x1,y1)和(x2,y2)的边e,请在O(1)时间中查找e是否位于任何矩形(包括边界)。

Also let me know of any data structures I can use for speedups! 还请让我知道我可以用于加速的任何数据结构! I'm also implementing this in java so I have easy access to hash sets, maps and all those nice data structures. 我也在Java中实现了此功能,因此我可以轻松访问哈希集,映射和所有这些不错的数据结构。

Since the rectangles are completely enclosed, the inside of each rectangle will simply be the CDT of the rectangle itself -- which is to say, two triangles, meeting along a diagonal of the rectangle. 由于矩形是完全封闭的,因此每个矩形的内部将只是矩形本身的CDT,也就是说,两个三角形沿着矩形的对角线相交。 So you can just insert all rectangles' diagonals (remember, two possible diagonals per rectangle) into a hashtable, and check which edges exactly match those endpoints. 因此,您只需将所有矩形的对角线(请记住,每个矩形有两个对角线)插入哈希表,然后检查哪些边缘与这些端点完全匹配。

It is possible to break up the area that all of the rectangles cover into a N by M grid of boxes. 可以将所有矩形覆盖的区域分解为N x M的框格。 By labeling each box with the rectangle it is in or the rectangles it overlaps. 通过用矩形标记每个框所在的矩形或重叠的矩形。 It is possible to obtain O(1) queries, with O(N*M) pre-processing. 通过O(N * M)预处理可以获得O(1)查询。

However, in order for it to work, the grid has to created based on an algorithm that allows for calculating which box a point lies in in O(1). 但是,为了使其工作,必须基于一种算法来创建网格,该算法允许计算点在O(1)中位于哪个框中。 It also requires that the number of rectangles a box overlaps be very small (ideally no more than 2 or 3) as otherwise the average query time could be O(log N) or worst. 它还要求一个框重叠的矩形的数量必须非常小(理想情况下不超过2或3个),否则平均查询时间可能为O(log N)或更糟。 This means that the number of boxes can get very large. 这意味着盒子的数量会非常大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM