M_Rhino_Geometry_Curve_TryGetCircle_1 - mcneel/rhinocommon-api-docs GitHub Wiki
Try to convert this curve into a Circle using a custom tolerance.
Namespace: Rhino.Geometry
Assembly: RhinoCommon (in RhinoCommon.dll) Version: Rhino 6.0
C#
public bool TryGetCircle(
out Circle circle,
double tolerance
)
VB
Public Function TryGetCircle (
<OutAttribute> ByRef circle As Circle,
tolerance As Double
) As Boolean
- circle
- Type: Rhino.Geometry.Circle
On success, the Circle will be filled in. - tolerance
- Type: System.Double
Tolerance to use when checking.
Type: Boolean
true if the curve could be converted into a Circle within tolerance.
VB
Partial Class Examples
Public Shared Function CircleCenter(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
Dim go As New Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter = Rhino.Input.[Custom].GeometryAttributeFilter.ClosedCurve
go.GetMultiple(1, 0)
If go.CommandResult() <> Rhino.Commands.Result.Success Then
Return go.CommandResult()
End If
Dim objrefs As Rhino.DocObjects.ObjRef() = go.Objects()
If objrefs Is Nothing Then
Return Rhino.Commands.Result.[Nothing]
End If
Dim tolerance As Double = doc.ModelAbsoluteTolerance
For i As Integer = 0 To objrefs.Length - 1
' get the curve geometry
Dim curve As Rhino.Geometry.Curve = objrefs(i).Curve()
If curve Is Nothing Then
Continue For
End If
Dim circle As Rhino.Geometry.Circle
If curve.TryGetCircle(circle, tolerance) Then
Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i + 1, circle.Center)
End If
Next
Return Rhino.Commands.Result.Success
End Function
End Class
C#
partial class Examples
{
public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc)
{
Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select objects");
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve;
go.GetMultiple(1, 0);
if( go.CommandResult() != Rhino.Commands.Result.Success )
return go.CommandResult();
Rhino.DocObjects.ObjRef[] objrefs = go.Objects();
if( objrefs==null )
return Rhino.Commands.Result.Nothing;
double tolerance = doc.ModelAbsoluteTolerance;
for( int i=0; i<objrefs.Length; i++ )
{
// get the curve geometry
Rhino.Geometry.Curve curve = objrefs[i].Curve();
if( curve==null )
continue;
Rhino.Geometry.Circle circle;
if( curve.TryGetCircle(out circle, tolerance) )
{
Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center);
}
}
return Rhino.Commands.Result.Success;
}
}
Python
import Rhino
import scriptcontext
def CircleCenter():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select objects")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
go.GetMultiple(1, 0)
if go.CommandResult()!=Rhino.Commands.Result.Success:
return go.CommandResult()
objrefs = go.Objects()
if not objrefs: return Rhino.Commands.Result.Nothing
tolerance = scriptcontext.doc.ModelAbsoluteTolerance
for i, objref in enumerate(objrefs):
# get the curve geometry
curve = objref.Curve()
if not curve: continue
rc, circle = curve.TryGetCircle( tolerance )
if rc:
print "Circle", i+1, ": center = ", circle.Center
return Rhino.Commands.Result.Success
if __name__=="__main__":
CircleCenter()
Supported in: 6.0.16224.21491, 5D58w