McNeel Wiki
Finding the Centers of Circles
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
Developer.NET
SummaryDemonstrates how to find the center point of a circle curve using the Rhino SDK.

Example

The following example code demonstrates how to find the center point of a circle curve using the Rhino SDK. In this is example, the center point is simply printed to the Rhino command line.

C#

  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    // Pick closed curves
    MRhinoGetObject go = new MRhinoGetObject();
    go.SetCommandPrompt("Select objects");
    go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
    go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_curve);
    go.GetObjects(1, 0);
    if (go.CommandResult() != IRhinoCommand.result.success)
      return go.CommandResult();


    for (int i = 0; i < go.ObjectCount(); i++)
    {
      // Get the curve geometry
      IOnCurve curve = go.Object(i).Curve();
      if (curve == null)
        continue;


      // Is the curve an arc curve?
      IOnArcCurve arc_curve = OnArcCurve.ConstCast(curve);
      if (arc_curve != null)
      {
        // Is the arc curve a circle
        if (arc_curve.IsCircle())
        {
          string sPoint = "";
          RhUtil.RhinoFormatPoint(arc_curve.m_arc.Center(), ref sPoint);
          RhUtil.RhinoApp().Print(string.Format("Circle{0}: center = ({1})\n", i+1, sPoint));
        }
      }
      else
      {
        // Does the curve look like a circle?
        OnPlane plane = new OnPlane();
        double tol = RhUtil.RhinoApp().ActiveDoc().AbsoluteTolerance();
        if (curve.IsPlanar(plane, tol))
        {
          OnArc arc = new OnArc();
          if (curve.IsArc(plane, arc, tol))
          {
            if (arc.IsCircle())
            {
              string sPoint = "";
              RhUtil.RhinoFormatPoint(arc.Center(), ref sPoint);
              RhUtil.RhinoApp().Print(string.Format("Circle{0}: center = ({1})\n", i+1, sPoint));
            }
          }
        }
      }
    }


    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload