Convert a Brep into a Sphere in GH?

If I have a (nurbs) sphere in Rhino and assigned it to a Brep component in GrassHopper, how do I retrieve the sphere as a Sphere type in GH? Is scripting the only or simplest way?

  var bb = Brep.GetBoundingBox(true);
  sph = new Sphere(bb.Center, (bb.Max.X - bb.Min.X) / 2);

// Rolf

Grasshopper doesn’t have spheres as a native type. It could have, after all RhinoCommon supports it, but GH doesn’t. Every sphere is stored as either a NurbsSurface or a RevSurface or a Brep.

Within the context of a script, you may of course want to convert such a surface or brep into a sphere. Your approach is fine, assuming you know that the input is a sphere. The Surface class in RhinoCommon also has a TryGetSphere() method you can use if you aren’t sure about the validity of the input.

OK thanks, that’ll be useful sometimes.

// Rolf

If you have a Brep with a single face then you can call TryGetSphere() on that face. If however you have a brep made up of several patches, yet the whole is definitely spherical, then you may be in trouble. Short of converting the brep to a point-cloud and fitting a sphere to that I do not know if there’s a good method available.

You can do that same thing in GH:

1 Like

But that still only gets you a Rhino.Geometry.Surface, not a Rhino.Geometry.Sphere.