How do I verify if a point is actually on a curve? Is there something similar to rs.PointCompare(point1, point2) but instead of comparing the 2 points to see if they are equal, it would compare the two objects and see if one is part of the other? At this point I just need to know if a point is on a curve.
Update:
I think I figured out the long way around it but still want to know if there’s a faster way, i…e. a specific function. Here is what I have done so far:
def IsPointOnCurve(MyCurve, MyPoint):
IsCurve = rs.IsCurve(MyCurve)
if IsCurve:
# Verify the point is on the curve
tClosestPoint = rs.CurveClosestPoint(MyCurve, MyPoint)
ClosestPointOnCurve = rs.EvaluateCurve(MyCurve, tClosestPoint)
return rs.PointCompare(MyPoint, ClosestPointOnCurve)
else: return False
First of all a tip how to format code here in a post:
pasting the code between 3 backticks ``` you get nicely formatted code:
def IsPointOnCurve(MyCurve, MyPoint):
IsCurve = rs.IsCurve(MyCurve)
if IsCurve:
# Verify the point is on the curve
tClosestPoint = rs.CurveClosestPoint(MyCurve, MyPoint)
ClosestPointOnCurve = rs.EvaluateCurve(MyCurve, tClosestPoint)
return rs.PointCompare(MyPoint, ClosestPointOnCurve)
else:
return False
About your question, see if the commented code below makes sense, else let us know
import rhinoscriptsyntax as rs
import scriptcontext as sc
curve_obj = rs.GetObject('select curve')
point_obj = rs.GetObject('get point')
# this gets the curve geometry object from the rhino object
curve = rs.coercecurve(curve_obj)
# curve is now a Rhino Curve object:
# https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Curve.htm
point = rs.PointCoordinates(point_obj)
# the curve object has a method to find the closest point within a tolerance
# https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_ClosestPoint.htm
# as we need to pass a tolerance to set what is still considered 'on the curve'
# we use the document tolerance for that
# Note: most of the rhinoscriptsyntax methods use that tolerance as well
tolerance = sc.doc.ModelAbsoluteTolerance
is_close, t = curve.ClosestPoint(point,tolerance)
print is_close
@Willem - Great comment on formatting code in the forum.
The docs say that Curve.ClosestPoint method only returns a boolean for success or failure. What does “is_close, t =…” do? The comma is throwing me off.
I never got my head around how exactly this works on the .NET side
However as you see in the doc there is a return value boolean and an ‘out’ parameter, that is the ‘t’ I’m catching as well.
NOTE that in python if a method returns multiple values you can separate them directly with the ‘,’ separator.
def get_xyz():
new_x = 10
new_y = 11
new_z = 12
return [new_x,new_y,new_z]
result = get_xyz()
x = result[0]
y = result[1]
z = result[2]
# or in one line:
x,y,z = get_xyz()