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.

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. :-)

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** p_{1}, p_{2}, p_{3} which are distinct, non-linear points

**Let** d_{1}, d_{2}, d_{3} be the linear distances between the points.

Use the Pythagorean Theorem to calculate them.

d = √( (p_{m}.x-p_{n}.x)^{2} + (p_{m}.y-p_{n}.y)^{2} )

**Let** a be the area of the triangle formed by the three points

Use Heron's Forumula to calculate it.

s = (d_{1} + d_{2} + d_{3}) ÷ 2

a = √( s(s-d_{1})(s-d_{2})(s-d_{3}) )

**Let** r be the radius of the circle

Using the formula

r = (d_{1}d_{2}d_{3}) ÷ (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.

Use the Pythagorean Theorem to calculate them.

d = √( (p

Use Heron's Forumula to calculate it.

s = (d

a = √( s(s-d

Using the formula

r = (d

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

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?

I'm pretty sure OP asked for equations dealing with

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.

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++.

Hope all goes well.

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

Hope all goes well.

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

Sorry for all these questions

Last edited on

Check out CGAL http://www.cgal.org/

For instance, this may be relevant: http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Bounding_volumes_ref/Class_Min_sphere_d.html

For instance, this may be relevant: http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Bounding_volumes_ref/Class_Min_sphere_d.html

Topic archived. No new replies allowed.