GhPython - Possible to Create & Read sphere radius?

Three GhPython questions, based on the desire to stay in ghdoc context avoiding to have to “bake” as long as possible. The things below (except for reading the sphere radius) I can do by baking into Rhino, and then use “plain RhinoCommon” functions, but as said, exactly that (baking) is what I would like to avoid since it’s “too early” to bake in the middle of a long GH process, (I will have to update very often) :

Q1: Is it possible to create a GH Sphere based on GH (non-baked) fit points similar to the following RhinoCommon command : Rhino.Geometry.Sphere.FitSphereToPoints(points) ?

It seems that Python has not implemented that variant of the Sphere command, but if there’s a way to tweak gh somehow, please let me know.

Q2: An option for Q1 exist, based on a GH component (Sphere Fit (SFit)) that can create a sphere from FitPoints (and I’m already creating the points in a GhPython Script component), but, how can I feed this SFit component from a GhPython Script component with the points without baking them into Rhino? (it’s too time consuming to create & bake so many points).

Q3: When I do have a GH reference to a Sphere in my GhPython code, how can I retrieve the radius of the Sphere? Also this sphere property seems to be missing in GhPython. :frowning: Any workaround?

// Rolf

Hi Rolf,

for Q2, if your points are done with GH, you should be able to transfer that as input to the SphereFit component without baking the points.

for Q3, if your sphere in GH is a surface, you can get a sphere object from it using python or a python component using various ways.

  1. Measure the curvature at an arbitrary point on the surface, this is the sphere radius
  2. Get the bounding box of the surface sphere, measure its size and multiply x 0.5
  3. Use Rhino.Geometry.Surface.TryGetSphere(srf, tolerance), then from the result, get the Radius property and the Center property.

does that help ?

c.

1 Like

@clement,
Q2 is OK, I solved that one.

Q3.1,2,3 - Why didn’t I think of those… :slight_smile:

Yes, thanks, your answers certainly was very helpful.

// Rolf

A fourth way, pick three random points from the surface and create a circle through it. You can then access the centre and radius fields of that circle.

1 Like