Curves don't consistently Extend, either to one side or not at all

Hi!
Been asking a bunch of questions lately, thanks for being patient with me :slight_smile:

I can’t show the entire code here, and it wouldn’t serve the purpose anyway, but I have a curve that I rebuilt before

                        select_edge = disc_edges[i]
                        select_reb = rg.PolylineCurve.Rebuild(select_edge, 2, 0, True)
                        if not cut_crv:
                            cut_crv.append(select_reb)

That curve stays the same during the iterations of the loop, and at a later part of the definition that curve is referenced, it should rotate once and have both versions (rotated and original) test against another curve - then select the needed curve and extend it:

                        ''' Cutting Line '''
                        cut_lines=[]
                        cut_pt_dis=[]
                        pt_i = random.randint(0, len(div_pt) - 1)
                        selected_pt = div_pt[pt_i]
                        line_ext = copy.deepcopy(cut_crv[0])
                        line_ext_r = copy.deepcopy(line_ext)
                        rotate = rg.Transform.Rotation(math.radians(90), mid_pt)
                        line_ext_r.Transform(rotate)
                        vec = rg.Line(mid_pt, selected_pt)
                        vec_dir = vec.Direction
                        move = rg.Transform.Translation(vec_dir)
                        line_ext.Transform(move)
                        cut_lines.append(line_ext)
                        line_ext_r.Transform(move)
                        cut_lines.append(line_ext_r)
                        for crv_test in cut_lines:
                            ctpt = crv_test.PointAt(0.6)
                            clt = rg.Curve.ClosestPoint(cut_crv[0], ctpt)
                            clpt = rg.Curve.PointAt(cut_crv[0], clt[1])
                            dispt = rg.Point3d.DistanceTo(ctpt, clpt)
                            cut_pt_dis.append(dispt)
                        sorted_cut_lines = [x for y, x in sorted(zip(cut_pt_dis, cut_lines))]
                        select_cut_line = sorted_cut_lines[1]
                        extended_line = select_cut_line.Extend(999, 999)

Now it all works, until I extend it after selecting the right one. Simply either nothing happens, or only one of the sides of the curve extends, doesn’t seem like there’s a logic error in the code (correct me if I’m wrong), seems more of a bug than anything else.

The original curve is highlighted and as you can see, it only extends one side:
image

Any ideas?

Edit: If I do a PointAt on both ends (0, 1) and build a Line, then transform this line into a NurbsCurve, then extend it - it works perfectly. But it’s such a stupid workaround to do every single time… Maybe it’s a problem with data types or some common thing with curves in Rhino?

Thanks a bunch,
Lev

1)Instead of selecting a random point from div_pt , selecting the midpoint of the bounding box of cut_crv might result in a more efficient implementation. This would eliminate the need to calculate the closest point on the curve for each line created, as well as the sorting step at the end.

2)It’s possible that the issue is with the Extend method. The Extend method in the RhinoCommon library can sometimes result in unexpected behavior.

One possible solution is to manually extend the line by a certain distance instead of using the Extend method. This can be done by creating two new points along the line’s direction, each a certain distance away from its endpoints, and creating a new line between these two points.

1 Like

Yeah thanks, it is unexpected seemingly for no reason.
I ended up creating a new Line from 2 points right before extending, and that seems to consistently work.
I did have to choose a random point from a specific list of points, it’s an integral part of it, but thank you for the tip, I’ll definitely still check it out!