Is there a way to extend and trim a pair of curves by each other to where they would/do intersect? I’m hoping to be able to treat them like if you used the fillet command with a 0 radius. It’s just a huge pain to have to test and correct curve directions to extend them in the right way.
Try the “Connect” command.
Thanks for the reply, but I meant in the context of python scripting. I could use the command function, but it’s kinda clunky.
Ahh, sorry, missed the Scripting category assignment.
Hi @Bailey
You could make a very simple method
x = (b2 - b1) / (m1 - m2)
y = m1 * x + b1
Based on the point p. you can then trim or extend.
This is the method :
def find_intersection(line1, line2):
m1, b1 = get_line_params(line1)
m2, b2 = get_line_params(line2)
x = (b2 - b1) / (m1 - m2)
y = m1 * x + b1
return Rhino.Geometry.Point3d(x, y, 0)
You can use it like this
def fancy_intersection(line1, line2):
# Get the parameters of the lines
m1, b1 = get_line_params(line1)
m2, b2 = get_line_params(line2)
x = (b2 - b1) / (m1 - m2)
y = m1 * x + b1
return Rhino.Geometry.Point3d(x, y, 0)
def ExtendTrimCurves():
curve1_id = rs.GetObject("Select first curve", rs.filter.curve)
curve2_id = rs.GetObject("Select second curve", rs.filter.curve)
if curve1_id is None or curve2_id is None:
return
curve1 = rs.coercecurve(curve1_id)
curve2 = rs.coercecurve(curve2_id)
line1 = Rhino.Geometry.Line(curve1.PointAtStart, curve1.PointAtEnd)
line2 = Rhino.Geometry.Line(curve2.PointAtStart, curve2.PointAtEnd)
intersection_point = fancy_intersection(line1, line2)
extension_length1 = curve1.PointAtEnd.DistanceTo(intersection_point)
extension_length2 = curve2.PointAtEnd.DistanceTo(intersection_point)
# Extend the curves
curve1_extended = curve1.Extend(Rhino.Geometry.CurveEnd.End, extension_length1, Rhino.Geometry.CurveExtensionStyle.Line)
curve2_extended = curve2.Extend(Rhino.Geometry.CurveEnd.End, extension_length2, Rhino.Geometry.CurveExtensionStyle.Line)
sc.doc.Objects.Add(curve1_extended)
sc.doc.Objects.Add(curve2_extended)
ExtendTrimCurves()