合并两个领域以得到一个新领域

皮尔佩尔

如何计算可能封装其他两个球体的最小球体?

每个球体都有一个3d空间中的中心点和一个半径。

编辑:

这是我的代码。我正在尝试实现merge()函数,但我不知道如何。

#include <gl\glm\glm.hpp>

class Sphere
{
public:
    Sphere();
    Sphere(const glm::vec3 &point, float radius);

    void set(const glm::vec3 &point, float radius);
    void reset();
    bool isReset() const;

    const glm::vec3& getCenter() const { return _point; }
    float radius() const { return _radius; }

    void merge(const Sphere &other);

    bool operator==(const Sphere &other) const {
        return (_point == other._point && _radius == other._radius);
    }
    bool operator!=(const Sphere &other) const {
        return !operator==(other);
    }

private:
    glm::vec3 _point;
    float _radius;
};
用户名

好吧,我讨厌glm,所以这只是数学。

假设您的两个球体具有半径r1, r2和中心c1, c2封闭球体的中心C半径为R

在此处输入图片说明

如果球体彼此包围:

|c1 - c2| + r1 < r2 反之亦然,以更大的范围为准。

否则,从图中可以清楚地看出

  • R = (r1 + r2 + |c1 - c2|) / 2
  • C = c1 + (c2 - c1) * (R - r1) / |c2 - c1| (线性插值)

哪里c1, c2, C向量,并且|v|是向量的大小v

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章