--原帖--
我正在尝试计算 3 维三角形的最小边界球。三角形由点point0,point1,point2给出。
对于样本输入 (0,0,10)、(0,10,0)、(10,0,0),以下代码给出:
radius = 8.164967,正确(使用谷歌Sketchup绘制模型验证)。
minSphereCenter = (10, 3.333..., 1.111...),这是不正确的。
正确的中心点是 (3.333..., 3.333..., 3.333...)。
我究竟做错了什么?
注意:我知道这不会给出钝角三角形的最小边界球。
- 解决方案 -
class Triangle{
Vector3f point0, point1, point2;
Vector3f minSphereCenter;
float minSphereRadius;
private void calculateMinimumBoundingSphere() {
minSphereRadius=
(point0.distance(point1)*point1.distance(point2)*point2.distance(point0))/
(2*(new Vector3f().cross(new Vector3f().sub(point0, point1), new Vector3f().sub(point1, point2)).length()));
float divisor=2*(new Vector3f().cross(new Vector3f().sub(point0, point1), new Vector3f().sub(point1, point2)).lengthSquared());
float
i=point1.distanceSquared(point2)*new Vector3f().sub(point0, point1).dot(new Vector3f().sub(point0, point2))/
divisor,
j=point0.distanceSquared(point2)*new Vector3f().sub(point1, point0).dot(new Vector3f().sub(point1, point2))/
divisor,
k=point0.distanceSquared(point1)*new Vector3f().sub(point2, point0).dot(new Vector3f().sub(point2, point1))/
divisor;
minSphereCenter=new Vector3f(point0).scale(i).add(new Vector3f(point1).scale(j)).add(new Vector3f(point2).scale(k));
System.out.println(minSphereCenter);
System.out.println(minSphereRadius);
}