比较 2 个 3D 对象的位置和大小。 (路亚)
我有两个 3d 对象。它们都是长方体。我需要检查两个对象是否有任何程度的相交。我知道一种缓慢且烦人的方法(检查左侧、右侧等)。我只需要能够判断该对象何时位于另一个对象的内部。
如果可以的话谢谢!任何伪代码表示赞赏!
I've got two 3d objects. They are both rectangular prisims. I need to check to see if the two objects are intersecting to any degree. I know a slow and annoying way (checking the left, right, etc.). I just need to be able to tell when the the object is inside of the other.
Thanks if you can! Any psuedo code is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解您所认为的“缓慢且烦人的方式”,但这听起来像是一种合理的方法,可以根据另一个对象的边界来测试每个面。如果两个棱镜在空间中任意定向,那确实没有错。但是,您可以在此之前进行快速而肮脏的检查,通过描述棱镜周围的球形边界框(球)并首先进行简单的距离检查,看看是否值得这样做 - 如果两个边界框没有接触(很容易)通过计算分离距离并对两个边界的两个半径求和来确定),那么您不必检查方向相关的交叉点。
I'm not sure I understand what you believe to be the 'slow and annoying way', but it sounds like a reasonable approach to test each face against the bounds of the other object. If the two prisms are oriented arbitrarily in space that's really not a wrong thing to do. However, you can do a quick and dirty check before that to see if its worth the expense by describing a spherical bounding box (ball) around the prism and doing a simple distance check first - if the two bounding boxes aren't touching (easily determined by calculating distance of separation and summing the two radii of the two bounds) then you don't have to check for orientation dependent intersections.