Sphere center and radius from 4 points

Dear all,

Do you know if there is any class or library that can help me to calculate the center and radius of a sphere from 4 known points on its surface?

Thank you in advance for any possible response.
Last edited on
Maybe there is something in the boost geometry libraries?

Do you know how to do it mathematically?

If not, I dreamt up this, not sure if it is right:

- 4 points create a spherical trapezium.
- cut the trapezium in half to form 2 spherical triangles.
- the plane defined by the 3 points in the triangle is at right angles to a normal of the sphere.
- calc the centre point of the triangle using plane geometry, the normal vector goes through this point.
- use the centre point and 2 points of the triangle to calc a cross product, which gives the normal vector
- do the same for the other spherical triangle
- the two normal intersect at the centre of the sphere
- calc the radius

If you do have to implement this yourself, I can see there is a bit of work in it. Unless there is a much easier way that I am not aware of.

Not sure if this is of any help at all, but I had a go. :-)
You only need three points on the circumference, and there is actually a pretty easy method.

Given p1, p2, p3 which are distinct, non-linear points

Let d1, d2, d3 be the linear distances between the points.
Use the Pythagorean Theorem to calculate them.

d = √( (pm.x-pn.x)2 + (pm.y-pn.y)2 )

Let a be the area of the triangle formed by the three points
Use Heron's Forumula to calculate it.

s = (d1 + d2 + d3) ÷ 2
a = √( s(s-d1)(s-d2)(s-d3) )

Let r be the radius of the circle
Using the formula

r = (d1d2d3) ÷ (4a)

Finally you can use the Pythagorean Theorem again to locate the center point of the circle. The only trick is to make sure you put it inside the circle. This is easy enough to figure because you only need identify the two points at the end of the longest edge identified in step one above, and make sure that the new center point is not on the same side of that edge as the remaining point.

Hope this helps.
Determine sphere from four points (which are not coplanar):
http://mysite.verizon.net/res148h4j/zenosamples/zs_sphere4pts.html

Determine family of spheres from three points (which are not colinear):
http://mathforum.org/library/drmath/view/51753.html
Cool, I didn't know those.

I'm pretty sure OP asked for equations dealing with circles, though. Did he change it?
Thank you all for your replies.

JLBorges, that's exactly what I wanted to know. But is there some classes that we can use directly (in VTK for example or any other library) to calculate that?

Thank you again.
Last edited on
I found this, which has some Java & C# code you could convert to C++.

http://stackoverflow.com/questions/13600739/calculate-centre-of-sphere-whose-surface-contains-4-points-c


Hope all goes well.
Thank you TheIdeaMan, I will check that.
It does not work because the four points are not exactly on the surface (a little error resulting from the sensors that acquire these points). I have to acquire more points and then fit them to a sphere. Could you have any source code for fitting a cloud of 3D points to a sphere (theoretically these points must be on the sphere surface with a small error)? I have googled it but I didn't find any code using c++.

Sorry for all these questions
Last edited on
Topic archived. No new replies allowed.