CurveLine intersection strange behavior

Hi all.

CurveLine_intersection_error.gh (12.5 KB)

The “ParameterB” (for the Line) value of the CurveIntersections event after a Rhino.Geometry.Intersect.Intersection.CurveLine method is giving unpredictable results.

In CurveLine the difference from the CurveCurve is that the Line is extended infinitely (is it?)
I would expect to have a parameter 0-1 if the intersection point is actually on the line and outside of the 0-1 domain if “outside”, not touching the starting finite Line object.

ParameterB give results as the Curve is used to make a boundingbox and increasing the line until it pierce out of the box (just a supposition).

I can’t use ParameterB (of a CurveLine intersection) at all… any examples available? Is it bugged?

On a second part, reading message box of the evaluate length component with [Normalized=false] i’ve seen this:
“1. Length factor cannot be smaller than the length of the curve.”
It should be corrected to:
“1. Length factor should be smaller than the length of the curve.”

Funky. Not much versed in C but seems like CurveLine intersection returns parameter on curve only, not on the line? But parameter on line (not curve) is what you’re after? Plus reparameterize? Alternatively I chose ParameterA then got the closest point on the line.

CurveLine_intersection_error2.gh (59.3 KB)

Yes. And i would expect reparametrizing of a line isn’t needed, as it is just a degree=1 segment from point to point, parameter should give the same result as evaluating normalized length.

Yes, I can use closest point to have a working parameter… sure.
But having to compute both, CurveLine and then CurveClosestPoint in a script will mean waste of resources.

We should be able to use “ParameterB” in some way.
I think it’s bugged… maybe.

This is true, the ParameterB value coming out of the curve intersection cannot be trusted. The intersector takes the line and moves and stretches it so that it guarantees overlap for the entire curve, and ultimately converts it into a LineCurve whose domain is probably (0 \mapsto \text{length}).

I’ll have a look at the code to see what can be done about this, but it’s probably not much more than just projecting the intersection point back onto the input line segment.

Thanks for the confirmation.
For now i’m going with something like this, then.

private void RunScript(Curve C, Line L, ref object P, ref object tC, ref object tL)
  {
List<Rhino.Geometry.Point3d> points;
List<double> CurveParameters;
List<double> LineParameters;
ItersectCurveLine(C, L, out points, out CurveParameters, out LineParameters);
P = points;
tC = CurveParameters;
tL = LineParameters;
  }

  // <Custom additional code> 
  public void ItersectCurveLine(Rhino.Geometry.Curve c, Rhino.Geometry.Line Ln,
  out List<Rhino.Geometry.Point3d> pts, out List<double> CurveParams, out List<double> LineParams){
double t = this.RhinoDocument.ModelAbsoluteTolerance;
List<Rhino.Geometry.Point3d> ps = new List<Rhino.Geometry.Point3d>();
List<double> CPs = new List<double>();
List<double> LPs = new List<double>();
Rhino.Geometry.Intersect.CurveIntersections ints = Rhino.Geometry.Intersect.Intersection.CurveLine(c, Ln, t, t);
for(int i = 0;i < ints.Count;i++){
  if(ints[i].IsPoint){
    Rhino.Geometry.Point3d p = ints[i].PointA;
    ps.Add(p);
    CPs.Add(ints[i].ParameterA);
    double len = Ln.Length;
    double d1 = Ln.PointAt(0).DistanceTo(p);
    double d2 = Ln.PointAt(1).DistanceTo(p);
    if(Math.Abs(d2 - len - d1) < t * 2) LPs.Add(-d1 / len);
    else LPs.Add(d1 / len);
  }
}
pts = ps;
CurveParams = CPs;
LineParams = LPs;
  }

CurveLine_intersection_error3.gh (6.2 KB)