# Differences

This shows you the differences between two versions of the page.

 — developer:sdksamples:iscircle [2015/09/14] (current) Line 1: Line 1: + ====== How To: Test if an Object is a Circle ====== + ====== C++, .NET ====== + > **Summary:​** //​Demonstrates 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 ===== + + 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# ===== + + 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; + } + + ​ + + + {{tag>​Developer cplusplus dotnet}}
developer/sdksamples/iscircle.txt ยท Last modified: 2015/09/14 (external edit)