--Original Post--
I'm trying to calculate the minimum bounding sphere for a 3-dimensional triangle. The triangle is given by the points point0, point1, point2.
The code below was created from http://en.wikipedia.org/wiki/Circumscribed_circle#Barycentric_coordinates_from_cross-_and_dot-products
For the sample input (0,0,10), (0,10,0), (10,0,0), the following code gives:
radius = 8.164967, which is correct (verified by using Google Sketchup to draw a model).
minSphereCenter = (10, 3.333..., 1.111...), which is incorrect.
The correct center point would be (3.333..., 3.333..., 3.333...).
What am I doing wrong?
Note: I know that this will not give the minimum bounding sphere for obtuse triangles.
--Solution--
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);
}
I've found the problem: The original minSphereCenter code used a scaleAdd() function, which I assumed worked like an addScale() function.
The original question has been edited with the solution.