M_Rhino_Geometry_Curve_GetDistancesBetweenCurves - mcneel/rhinocommon-api-docs GitHub Wiki
Computes the distances between two arbitrary curves that overlap.
Namespace: Rhino.Geometry
Assembly: RhinoCommon (in RhinoCommon.dll) Version: Rhino 6.0
C#
public static bool GetDistancesBetweenCurves(
Curve curveA,
Curve curveB,
double tolerance,
out double maxDistance,
out double maxDistanceParameterA,
out double maxDistanceParameterB,
out double minDistance,
out double minDistanceParameterA,
out double minDistanceParameterB
)
VB
Public Shared Function GetDistancesBetweenCurves (
curveA As Curve,
curveB As Curve,
tolerance As Double,
<OutAttribute> ByRef maxDistance As Double,
<OutAttribute> ByRef maxDistanceParameterA As Double,
<OutAttribute> ByRef maxDistanceParameterB As Double,
<OutAttribute> ByRef minDistance As Double,
<OutAttribute> ByRef minDistanceParameterA As Double,
<OutAttribute> ByRef minDistanceParameterB As Double
) As Boolean
- curveA
- Type: Rhino.Geometry.Curve
A curve. - curveB
- Type: Rhino.Geometry.Curve
Another curve. - tolerance
- Type: System.Double
A tolerance value. - maxDistance
- Type: System.Double
The maximum distance value. This is an out reference argument. - maxDistanceParameterA
- Type: System.Double
The maximum distance parameter on curve A. This is an out reference argument. - maxDistanceParameterB
- Type: System.Double
The maximum distance parameter on curve B. This is an out reference argument. - minDistance
- Type: System.Double
The minimum distance value. This is an out reference argument. - minDistanceParameterA
- Type: System.Double
The minimum distance parameter on curve A. This is an out reference argument. - minDistanceParameterB
- Type: System.Double
The minimum distance parameter on curve B. This is an out reference argument.
Type: Boolean
true if the operation succeeded; otherwise false.
VB
Imports Rhino
Imports Rhino.Commands
Imports Rhino.DocObjects
Imports Rhino.Geometry
Imports System.Drawing
Imports Rhino.Input
Namespace examples_vb
Class DeviationConduit
Inherits Rhino.Display.DisplayConduit
Private ReadOnly _curveA As Curve
Private ReadOnly _curveB As Curve
Private ReadOnly _minDistPointA As Point3d
Private ReadOnly _minDistPointB As Point3d
Private ReadOnly _maxDistPointA As Point3d
Private ReadOnly _maxDistPointB As Point3d
Public Sub New(curveA As Curve, curveB As Curve, minDistPointA As Point3d, minDistPointB As Point3d, maxDistPointA As Point3d, maxDistPointB As Point3d)
_curveA = curveA
_curveB = curveB
_minDistPointA = minDistPointA
_minDistPointB = minDistPointB
_maxDistPointA = maxDistPointA
_maxDistPointB = maxDistPointB
End Sub
Protected Overrides Sub DrawForeground(e As Rhino.Display.DrawEventArgs)
e.Display.DrawCurve(_curveA, Color.Red)
e.Display.DrawCurve(_curveB, Color.Red)
e.Display.DrawPoint(_minDistPointA, Color.LawnGreen)
e.Display.DrawPoint(_minDistPointB, Color.LawnGreen)
e.Display.DrawLine(New Line(_minDistPointA, _minDistPointB), Color.LawnGreen)
e.Display.DrawPoint(_maxDistPointA, Color.Red)
e.Display.DrawPoint(_maxDistPointB, Color.Red)
e.Display.DrawLine(New Line(_maxDistPointA, _maxDistPointB), Color.Red)
End Sub
End Class
Public Class CurveDeviationCommand
Inherits Command
Public Overrides ReadOnly Property EnglishName() As String
Get
Return "vbCurveDeviation"
End Get
End Property
Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
doc.Objects.UnselectAll()
Dim objRef1 As ObjRef = Nothing
Dim rc1 = RhinoGet.GetOneObject("first curve", True, ObjectType.Curve, objRef1)
If rc1 <> Result.Success Then
Return rc1
End If
Dim curveA As Curve = Nothing
If objRef1 IsNot Nothing Then
curveA = objRef1.Curve()
End If
If curveA Is Nothing Then
Return Result.Failure
End If
' Since you already selected a curve if you don't unselect it
' the next GetOneObject won't stop as it considers that curve
' input, i.e., curveA and curveB will point to the same curve.
' Another option would be to use an instance of Rhino.Input.Custom.GetObject
' instead of Rhino.Input.RhinoGet as GetObject has a DisablePreSelect() method.
doc.Objects.UnselectAll()
Dim objRef2 As ObjRef = Nothing
Dim rc2 = RhinoGet.GetOneObject("second curve", True, ObjectType.Curve, objRef2)
If rc2 <> Result.Success Then
Return rc2
End If
Dim curveB As Curve = Nothing
If objRef2 IsNot Nothing Then
curveB = objRef2.Curve()
End If
If curveB Is Nothing Then
Return Result.Failure
End If
Dim tolerance = doc.ModelAbsoluteTolerance
Dim maxDistance As Double
Dim maxDistanceParameterA As Double
Dim maxDistanceParameterB As Double
Dim minDistance As Double
Dim minDistanceParameterA As Double
Dim minDistanceParameterB As Double
Dim conduit As DeviationConduit
If Not Curve.GetDistancesBetweenCurves(curveA, curveB, tolerance, maxDistance, maxDistanceParameterA, maxDistanceParameterB, _
minDistance, minDistanceParameterA, minDistanceParameterB) Then
RhinoApp.WriteLine("Unable to find overlap intervals.")
Return Result.Success
Else
If minDistance <= RhinoMath.ZeroTolerance Then
minDistance = 0.0
End If
Dim maxDistPtA = curveA.PointAt(maxDistanceParameterA)
Dim maxDistPtB = curveB.PointAt(maxDistanceParameterB)
Dim minDistPtA = curveA.PointAt(minDistanceParameterA)
Dim minDistPtB = curveB.PointAt(minDistanceParameterB)
conduit = New DeviationConduit(curveA, curveB, minDistPtA, minDistPtB, maxDistPtA, maxDistPtB)
conduit.Enabled = True
doc.Views.Redraw()
RhinoApp.WriteLine("Minimum deviation= {0} pointA= {1}, pointB= {2}", minDistance, minDistPtA, minDistPtB)
RhinoApp.WriteLine("Maximum deviation= {0} pointA= {1}, pointB= {2}", maxDistance, maxDistPtA, maxDistPtB)
End If
Dim str As String = ""
RhinoGet.GetString("Press Enter when done", True, str)
conduit.Enabled = False
Return Result.Success
End Function
End Class
End Namespace
C#
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using System.Drawing;
using Rhino.Input;
namespace examples_cs
{
class DeviationConduit : Rhino.Display.DisplayConduit
{
private readonly Curve m_curve_a;
private readonly Curve m_curve_b;
private readonly Point3d m_min_dist_point_a ;
private readonly Point3d m_min_dist_point_b ;
private readonly Point3d m_max_dist_point_a ;
private readonly Point3d m_max_dist_point_b ;
public DeviationConduit(Curve curveA, Curve curveB, Point3d minDistPointA, Point3d minDistPointB, Point3d maxDistPointA, Point3d maxDistPointB)
{
m_curve_a = curveA;
m_curve_b = curveB;
m_min_dist_point_a = minDistPointA;
m_min_dist_point_b = minDistPointB;
m_max_dist_point_a = maxDistPointA;
m_max_dist_point_b = maxDistPointB;
}
protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
{
e.Display.DrawCurve(m_curve_a, Color.Red);
e.Display.DrawCurve(m_curve_b, Color.Red);
e.Display.DrawPoint(m_min_dist_point_a, Color.LawnGreen);
e.Display.DrawPoint(m_min_dist_point_b, Color.LawnGreen);
e.Display.DrawLine(new Line(m_min_dist_point_a, m_min_dist_point_b), Color.LawnGreen);
e.Display.DrawPoint(m_max_dist_point_a, Color.Red);
e.Display.DrawPoint(m_max_dist_point_b, Color.Red);
e.Display.DrawLine(new Line(m_max_dist_point_a, m_max_dist_point_b), Color.Red);
}
}
public class CurveDeviationCommand : Command
{
public override string EnglishName { get { return "csCurveDeviation"; } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
doc.Objects.UnselectAll();
ObjRef obj_ref1;
var rc1 = RhinoGet.GetOneObject("first curve", true, ObjectType.Curve, out obj_ref1);
if (rc1 != Result.Success)
return rc1;
Curve curve_a = null;
if (obj_ref1 != null)
curve_a = obj_ref1.Curve();
if (curve_a == null)
return Result.Failure;
// Since you already selected a curve if you don't unselect it
// the next GetOneObject won't stop as it considers that curve
// input, i.e., curveA and curveB will point to the same curve.
// Another option would be to use an instance of Rhino.Input.Custom.GetObject
// instead of Rhino.Input.RhinoGet as GetObject has a DisablePreSelect() method.
doc.Objects.UnselectAll();
ObjRef obj_ref2;
var rc2 = RhinoGet.GetOneObject("second curve", true, ObjectType.Curve, out obj_ref2);
if (rc2 != Result.Success)
return rc2;
Curve curve_b = null;
if (obj_ref2 != null)
curve_b = obj_ref2.Curve();
if (curve_b == null)
return Result.Failure;
var tolerance = doc.ModelAbsoluteTolerance;
double max_distance;
double max_distance_parameter_a;
double max_distance_parameter_b;
double min_distance;
double min_distance_parameter_a;
double min_distance_parameter_b;
DeviationConduit conduit;
if (!Curve.GetDistancesBetweenCurves(curve_a, curve_b, tolerance, out max_distance,
out max_distance_parameter_a, out max_distance_parameter_b,
out min_distance, out min_distance_parameter_a, out min_distance_parameter_b))
{
RhinoApp.WriteLine("Unable to find overlap intervals.");
return Result.Success;
}
else
{
if (min_distance <= RhinoMath.ZeroTolerance)
min_distance = 0.0;
var max_dist_pt_a = curve_a.PointAt(max_distance_parameter_a);
var max_dist_pt_b = curve_b.PointAt(max_distance_parameter_b);
var min_dist_pt_a = curve_a.PointAt(min_distance_parameter_a);
var min_dist_pt_b = curve_b.PointAt(min_distance_parameter_b);
conduit = new DeviationConduit(curve_a, curve_b, min_dist_pt_a, min_dist_pt_b, max_dist_pt_a, max_dist_pt_b) {Enabled = true};
doc.Views.Redraw();
RhinoApp.WriteLine("Minimum deviation = {0} pointA({1}), pointB({2})", min_distance, min_dist_pt_a, min_dist_pt_b);
RhinoApp.WriteLine("Maximum deviation = {0} pointA({1}), pointB({2})", max_distance, max_dist_pt_a, max_dist_pt_b);
}
var str = "";
RhinoGet.GetString("Press Enter when done", true, ref str);
conduit.Enabled = false;
return Result.Success;
}
}
}
Python
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
def RunCommand():
crvA = rs.GetCurveObject("first curve")[0]
crvA = rs.coercecurve(crvA)
crvB = rs.GetCurveObject("second curve")[0]
crvB = rs.coercecurve(crvB)
if crvA == None or crvB == None:
return Rhino.Commands.Result.Failure
maxa, maxb, maxd, mina, minb, mind = rs.CurveDeviation(crvA, crvB)
if mind <= Rhino.RhinoMath.ZeroTolerance:
mind = 0.0;
maxDistPtA = crvA.PointAt(maxa)
maxDistPtB = crvB.PointAt(maxb)
minDistPtA = crvA.PointAt(mina)
minDistPtB = crvB.PointAt(minb)
print "Minimum deviation = {0} pointA({1}, {2}, {3}), pointB({4}, {5}, {6})".format(
mind, minDistPtA.X, minDistPtA.Y, minDistPtA.Z, minDistPtB.X, minDistPtB.Y, minDistPtB.Z)
print "Maximum deviation = {0} pointA({1}, {2}, {3}), pointB({4}, {5}, {6})".format(
maxd, maxDistPtA.X, maxDistPtA.Y, maxDistPtA.Z, maxDistPtB.X, maxDistPtB.Y, maxDistPtB.Z)
if __name__=="__main__":
RunCommand()
Supported in: 6.0.16224.21491, 5D58w