如何計算封裝另外兩個球體的最小球體?合併兩個球體以獲得新球體
每個球體在三維空間和半徑中都有一箇中心點。
編輯:
這是我的代碼。我試圖實現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;
};
這不是特定語言和太寬泛。顯示你的代碼。 – Olaf
將數學轉化爲代碼需要幫助嗎?如果你確實向我們展示了你到目前爲止所擁有的東西。如果你需要數學方面的幫助,你幾乎肯定會問錯誤的地方。 –
我編輯了我的帖子。這不應該太難,所以我想我應該問這裏。 – Pilpel