检测直角棱镜的重叠 [英] Detect overlapping of rectangular prisms

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

问题描述

给定一个 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 相交,则否定不完全向右、向左、向上、向下等.

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天全站免登陆