Why is this "Intersect Lines" sample code not working for me?

Hi Friends,

I’m trying to find the intersection between two curves using the sample code of “Intersect Lines” from here.

null

I select the two (non-parallel) lines in rhino and then in VS,
go.Object(0).Geometry() and go.Object(1).Geometry() do represent the lines in Rhino but then trying to assigns these values to crv0 and crv1 is making them null…

The lines are two simple, two points, degree 1 lines.

Any idea?

Many Thanks in advance,

Roy.

Looks like it depends if you draw with Curve a degree-1 2-control point curve or with the command Line.
The former will not produce a line curve, the latter will. You can inspect the object with the What command. The information should contain the word Line. If you run SimplefyCurve on your input curves first, they also turn into lines.

Alternatively, you can do this in code, which works in both cases.

      Curve c0 = go.Object(0).Curve();
      Curve c1 = go.Object(1).Curve();


      Line line0, line1;
      if (c0.IsLinear(doc.ModelAbsoluteTolerance) && c1.IsLinear(doc.ModelAbsoluteTolerance))
      {
        line0 = new Line(c0.PointAtStart, c0.PointAtEnd);
        line1 = new Line(c1.PointAtStart, c1.PointAtEnd);
      }
      else
      {
        return Rhino.Commands.Result.Failure;
      }

      Vector3d v0 = line0.Direction;
      v0.Unitize();
      Vector3d v1 = line1.Direction;
      v1.Unitize();

Thanks a lot Menno,

I know what you mean but I actually drew the lines using the “Polyline” command, I drew one segment and then ended the command… so I expected the result to be simple lines that would work but they didn’t.

Then I drew two simple lines again using the “Line” command and it did work…
The “What” command actually said: “Valid curve. Line.” for both commands (“Line” and Polyline") but again it only worked when the lines were made by the “Line” command so I still wondered what’s going on.

Thanks for the “SimplifyCrv” tip, I know the command but I was wondering what is happening to a line of two points that was created by the “Polyline” command, Rhino says it does simplify it.
It can’t simplify a Line that was made by the Line command.

Thanks for the code example too. It’s good to know although eventually it turned out that in the project that I’m working on I already got lines that do work with the example code, The issue arose only when I tested the example code by itself and drew these lines (using the polyline command) that didn’t work…

Best Regards,

Roy.

Huh, that is even more weird, I see that too.

Polyline → What shows ‘line’, but it is not a LineCurve.
Line → What shows ‘line’, and it is a LineCurve.

@dale I think this is quite counter intuitive. Also the code sample may need tuning up?

What is intended to be user-friendly. If you need real details, use List.

– Dale

Ah, right. There it is ON_PolylineCurve and ON_LineCurve , thanks for pointing that out.