Intersecting two spheres C++


I was wondering what the fastest method to create and intersect two spheres is? I have to do this hundreds of times in a loop and it is going pretty slowly…so what I am doing is

  1. Creating two ON_Sphere
  2. Transforming them into breps using their GetNurbForm method:
  3. Intersecting those two breps with RhinoIntersectBreps().

As I said…pretty slow process… can I speed it up?


P.S. My ON_Sphere->ON_Brep* transformation looks like this:

ON_Sphere sphere(centerpt, radius);

ON_NurbsSurface spheresrf;
sphere.GetNurbForm( spheresrf );

ON_Surface* srf = spheresrf.Duplicate();
ON_Brep* brep = ON_Brep::New();
brep->Create( srf );
delete srf;
srf = 0;

This can be solved in an exact manner. There is such a function in RhinoCommon

I’m sure there must also be one in C++, check the headers!

Sure is. Use the version of ON_Intersect that accepts spheres (ON_Sphere) as arguments.

Does this help?

– Dale

1 Like