# 如何判断对象是否封闭

## 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;
}```
zh/developer/sdksamples/iscircle.txt · Last modified: 2020/08/14 (external edit)