检测矩形棱镜的重叠 [英] Detect overlapping of rectangular prisms

查看:137
本文介绍了检测矩形棱镜的重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个3D坐标系和一个具有非负起始点和一个非负尺寸(例如,从(0, 2, 5)开始且尺寸为(9, 20, 5))的矩形棱镜:如何最好地检查是否另一个矩形棱镜与已经在坐标系中的棱镜之一相交?最终,目标是对所有存在的棱镜进行此项检查,能够测试一个棱镜就足以完成这项任务.

Given a 3D coordinate system and rectangular prisms with a non-negative starting point and a non-negative size (e.g. starts at (0, 2, 5) and has a size of (9, 20, 5)): how can I best check if another rectangular prism intersects with one of the prisms already in the coordinate system? Eventually, the goal would be to perform this check for all prisms present, being able to test one should be sufficient to complete this task.

信息:起始点和大小为3个元组的非负多头.我正在寻找一种速度适中的优雅解决方案.

Info: starting points and sizes are 3-tuples of non-negative longs. I am looking for an elegant solution that is moderately fast.

我的项目使用Java,但是任何数学公式,伪代码或描述都绰绰有余.

My project is in java, but any math formula, pseudo code or description is more than enough.

推荐答案

假设您有两个棱镜A和B.如果B与A相交,那就是没有完全位于右边,左边,上边,下边等等. /p>

Lets say you have two prisms A and B. If B intersects A it's the negation of not being completely to the right, left, up, down etc.

if not (B.x > A.x+A.dx or B.x+B.dx < A.x or
        B.y > A.y+A.dy or B.y+B.dy < A.y or
        B.z > A.z+A.dz or B.z+B.dz < A.z)
        // B intersects A

这篇关于检测矩形棱镜的重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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