McNeel Wiki
How To: Test if an Object is a Circle
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++, .NET
SummaryDemonstrates how to test if an object looks like a circle.

C++

  bool IsCircle( const CRhinoObject* obj )
  {
    bool rc = false;
    if( obj )
    {
      // Is the object a circle?
      if( const ON_ArcCurve* arc = ON_ArcCurve::Cast(obj->Geometry()) )
      {
        if( arc->IsCircle() )
          rc = true;
      }
      // Is the object an curve that just looks like a circle?
      else if( const ON_Curve* crv = ON_Curve::Cast(obj->Geometry()) )
      {
        ON_NurbsCurve nurb;
        if( crv->GetNurbForm(nurb) )
        {
          ON_Arc arc;
          double tol = ::RhinoApp().ActiveDoc()->AbsoluteTolerance();
          if( nurb.IsArc(0, &arc, tol) && arc.IsCircle()  )
            rc = true;
        }
      }
    }
    return rc;
  }

VB.NET (Rhino 4)

  Function IsCircle(ByVal obj As IRhinoObject) As Boolean
    Dim rc As Boolean = False
    If (obj IsNot Nothing) Then
      ' Is the object a circle?
      Dim arc_crv As IOnArcCurve = OnArcCurve.ConstCast(obj.Geometry())
      If (arc_crv IsNot Nothing) Then
        rc = arc_crv.IsCircle()
      Else
        ' Is the object a curve that just looks like a circle?
        Dim crv As IOnCurve = OnCurve.ConstCast(obj.Geometry())
        If (crv IsNot Nothing) Then
          Dim plane As New OnPlane()
          Dim tol As Double = RhUtil.RhinoApp.ActiveDoc.AbsoluteTolerance()
          If (crv.IsPlanar(plane, tol)) Then
            Dim arc As New OnArc
            If (crv.IsArc(plane, arc, tol)) Then
              rc = arc.IsCircle()
            End If
          End If
        End If
      End If
    End If
    Return rc
  End Function

C# (Rhino 4)

  private bool IsCircle(IRhinoObject obj)
  {
    bool rc = false;
    if( obj != null )
    {
      // Is the object a circle?
      IOnArcCurve arc_crv = OnArcCurve.ConstCast(obj.Geometry());
      if(arc_crv != null)
        rc = arc_crv.IsCircle();
      else
      {
        // Is the object an curve that just looks like a circle?
        IOnCurve crv = OnCurve.ConstCast(obj.Geometry());
        if(crv != null)
        {
          OnPlane plane = new OnPlane();
          double tol = RhUtil.RhinoApp().ActiveDoc().AbsoluteTolerance();
          if(crv.IsPlanar(plane, tol))
          {
            OnArc arc = new OnArc();
            if(crv.IsArc(plane, arc, tol))
              rc = arc.IsCircle();
          }
        }
      }
    }
    return rc;
  }
rename · changes · history · subscriptions · lost and found · references · file upload