在计算边界球半径时遇到一点问题 [英] Having a little issue calculating the bounding sphere radius

查看:123
本文介绍了在计算边界球半径时遇到一点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法通过两种方法来计算边界球半径,但是没有一种方法能够准确地给出我想要的.我不需要像素"完美的包围球,但我想要的东西比我现在拥有的要好.

我正在使用Wavefront .obj模型并计算这些模型的边界球半径,我提取了当前模型的尺寸(我正在使用Nate Robbins的GLM库),这将为我提供每个轴上的尺寸. /p>

第一种方法: 将每个轴除以2,这将为我提供每个轴的半径.最大的是我将用于边界球的那个.这将适用于我项目中的大多数对象.它不适用于某些形状,例如立方体形状的形状.基本上,如果我有一个立方体并使用这种方法计算半径,球体将把立方体的角留在外面.

第二种方法: 将每个轴除以2,这将为我提供每个轴的半径.然后,执行此操作以取出边界球的半径:

r = SQRT(x*x + y*y + z*z)

但这给了我很大的半径.该对象将完全封闭在球体内,但球体非常大,超出了应有的大小.

据我所知,我不理解我在上面的公式中做错了什么.但是我显然错了...

解决方案

您的第二种方法应该为您的边界框提供边界球,但是正如您所发现的,它会比其他任何东西都大.

可以通过平移模型点来找到更好的边界球,以便使用已经拥有的边界框尺寸将模型点定在原点上,然后为每个单独的顶点计算原点的半径对于这一点,使用sqrt(x*x + y*y + z*z)公式.其中最大的是您的边界球半径.

请注意,这将不是最佳的边界球.为此,您必须找到模型的凸包,并使用诸如旋转卡尺之类的东西来选择球体的最佳中心点.

要以2D形式显示,红色轮廓是形状的边界框,蓝色圆圈是该框的边界圈.使用多边形顶点并以框为中心的改进的圆形为绿色.请注意,黑色多边形的所有点都不会碰到蓝色圆圈.

I have managed to calculate the bounding sphere radius in two ways, but none is giving me exactly what I want. I don't need a "pixel" perfect bounding sphere but I would like something better than what I currently have.

I'm using Wavefront .obj models and to calculate the bounding sphere radius for those models I extract the current model dimensions (I'm using the GLM library from Nate Robbins) which will give me the dimension on each axis.

First approach: Divide each axis by 2 and that will give me the radius on each axis. The largest is the one I'll use for my bounding sphere. This will work for most objects specific to my project. It will not work for some, like cube-shaped ones. Basically, if I have a cube and calculate the radius with this approach, the sphere will leave the cube corners outside.

Second approach: Divide each axis by 2 and that will give me the radius on each axis. Then I do this to take out the radius for the bounding sphere:

r = SQRT(x*x + y*y + z*z)

But this gives me a pretty large radius. The object will be totally enclosed in the sphere but the sphere is pretty large, more than it should be.

I don't understand what I'm doing wrong in the formula above, as far as I know it, it should work. But I'm obviously wrong...

解决方案

Your second approach should give you the bounding sphere for your bounding box, but as you discovered, it will be larger than necessary for anything other than a box.

A better bounding sphere can be found by translating the model points so they're centered on the origin using the bounding box dimensions you already have, then for each individual vertex calculate the radius from the origin for that point using the sqrt(x*x + y*y + z*z) formula. Whichever of those is the largest is the radius of your bounding sphere.

Note that this won't be the optimal bounding sphere. For that you'd have to find the convex hull of your model and use something like rotating calipers to pick the optimal center point for the sphere.

To show it in 2D, the red outline is the bounding box of the shape, and the blue circle is the bounding circle of the box. The improved circle using the polygon vertices, and centered on the box is green. Note that none of the points of the black polygon touch the blue circle.

这篇关于在计算边界球半径时遇到一点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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