检查两个矩形是否重叠或边缘是否接触
Check if two rectangles overlap or the edges touch
我得到lon和lat的地理坐标,如西北和东南lon/lat。所以,当我得到它们时,我翻译成公制。所以在这里我得到了我的第一个矩形,north_west和south_east坐标,然后我有具有北、南、西和东坐标的相同公制系统的边界矩形。我需要在边缘接触内的交叉点上检查这两个矩形,我写了什么:
bool filter(TilePosition const& tile_position) const noexcept override
{
MetricBoundingBox tile_bounds{tile_position};
bool cond1 = (tile_bounds.north <= south_east_.lon);
bool cond2 = (tile_bounds.south >= north_west_.lon);
bool cond3 = (tile_bounds.west <= south_east_.lat);
bool cond4 = (tile_bounds.east >= north_west_.lat);
return cond1 && cond2 && cond3 && cond4;
}
我不确定我做得对不对?我的要求是,如果第二个矩形的边界与第一个矩形的边界相交,则必须保留第二个矩形。否则,过滤。
您的解决方案不正确。
除了混淆纬度和经度的含义之外,您还有一个基本问题,即为笛卡尔坐标空间设计的算法在圆柱坐标中不起作用,因为经度是周期性的。 对于靠近子午线的矩形,情况可能看起来不错,但是当您在环绕点(+/- 180度经度)附近开始测试时,此方法将失败。
一个简单的解决方法是将穿过包装点的每个矩形分成两个不交叉的矩形。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- 如何在c/c++中检查两个任意内存范围是否重叠
- 是否有快捷方式重叠运算符?
- 多个线程/进程是否可以在不同步的情况下同时从/写入文件的非重叠区域?
- 如何检查 n 个给定的磁贴中是否有任何重叠
- Xlib.检查窗口是否重叠
- 检查两个矩形是否重叠或边缘是否接触
- 测试方形是否与 C++ 中带有 DirectX 的多边形重叠(可选)
- std::copy_n 是否适用于重叠范围?
- 在读取期间,非重叠串行端口连接是否会阻止写入(反之亦然)
- 如何在c++中检查两个或多个时间段是否重叠
- 是否允许 memcpy 的 src 和 dest 参数重叠
- 缓冲区中的TCP数据是否可以重叠
- malloc()是否可以分配一个与使用mmap()分配的另一个缓冲区重叠的缓冲区
- 是否可以有效地计数与数字线上的单个点P重叠的线段的数量
- 存储一组不重叠的范围,并严格查找一个值是否存在于任何一个范围中
- 如何确定一组矩形是否包含两个重叠区域
- 在小于0 (N)的时间内找出点是否在N个(可能重叠)矩形中的一个内
- Qt:是否允许非矩形QWidget重叠