﻿Intersection.LineLine Method (Line, Line, Double, Double)
 IntersectionLineLine Method (Line, Line, Double, Double)
Finds the closest point between two infinite lines.

Namespace: Rhino.Geometry.Intersect
Assembly: RhinoCommon (in RhinoCommon.dll) Version: 5.1.50000.0 (5.0.20693.0)
Syntax
```public static bool LineLine(
Line lineA,
Line lineB,
out double a,
out double b
)```

#### Parameters

lineA
Type: Rhino.GeometryLine
First line.
lineB
Type: Rhino.GeometryLine
Second line.
a
Type: SystemDouble
Parameter on lineA that is closest to lineB. The shortest distance between the lines is the chord from lineA.PointAt(a) to lineB.PointAt(b)
b
Type: SystemDouble
Parameter on lineB that is closest to lineA. The shortest distance between the lines is the chord from lineA.PointAt(a) to lineB.PointAt(b)

#### Return Value

Type: Boolean
true if points are found and false if the lines are numerically parallel. Numerically parallel means the 2x2 matrix:

+AoA -AoB

-AoB +BoB

is numerically singular, where A = (lineA.To - lineA.From) and B = (lineB.To-lineB.From)
Examples
```using Rhino.Geometry;

partial class Examples
{
public static Rhino.Commands.Result IntersectLines(Rhino.RhinoDoc doc)
{
Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt( "Select lines" );
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
go.GetMultiple( 2, 2);
if( go.CommandResult() != Rhino.Commands.Result.Success )
return go.CommandResult();
if( go.ObjectCount != 2 )
return Rhino.Commands.Result.Failure;

LineCurve crv0 = go.Object(0).Geometry() as LineCurve;
LineCurve crv1 = go.Object(1).Geometry() as LineCurve;
if( crv0==null || crv1==null )
return Rhino.Commands.Result.Failure;

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

if( v0.IsParallelTo(v1) != 0 )
{
Rhino.RhinoApp.WriteLine("Selected lines are parallel.");
return Rhino.Commands.Result.Nothing;
}

double a, b;
if( !Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1, out a, out b))
{
Rhino.RhinoApp.WriteLine("No intersection found.");
return Rhino.Commands.Result.Nothing;
}

Point3d pt0 = line0.PointAt(a);
Point3d pt1 = line1.PointAt(b);
// pt0 and pt1 should be equal, so we will only add pt0 to the document
doc.Views.Redraw();
return Rhino.Commands.Result.Success;
}
}```
```import Rhino
import scriptcontext

def IntersectLines():
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt( "Select lines" )
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.GetMultiple( 2, 2)
if go.CommandResult()!=Rhino.Commands.Result.Success:
return go.CommandResult()
if go.ObjectCount!=2: return Rhino.Commands.Result.Failure

crv0 = go.Object(0).Geometry()
crv1 = go.Object(1).Geometry()
if not crv0 or not crv1: return Rhino.Commands.Result.Failure

line0 = crv0.Line
line1 = crv1.Line
v0 = line0.Direction
v0.Unitize()
v1 = line1.Direction
v1.Unitize()

if v0.IsParallelTo(v1)!=0:
print "Selected lines are parallel."
return Rhino.Commands.Result.Nothing

rc, a, b = Rhino.Geometry.Intersect.Intersection.LineLine(line0, line1)
if not rc:
print "No intersection found."
return Rhino.Commands.Result.Nothing

pt0 = line0.PointAt(a)
pt1 = line1.PointAt(b)
# pt0 and pt1 should be equal, so we will only add pt0 to the document