JimYuan's Blog

Sharing the things I learned

0%

LinesIntersection_in_3D

Intersection in 3D

According to this post

Most 3D lines do not intersect. A reliable method is to find the shortest line between two 3D lines. If the shortest line has a lenght of zero(or less than whatever tolerance you specify) then you know that the two original lines intersect.

Therefore, the question become

How can we find the shortest line between two 3D lines.

Check this article by Paul
Two examples I read

In short, this article introduced two thoughts/ implementation to get the minimal distance between two 3D lines.

  1. Write down the lenght of the line segment joining the two lines and then find the minimum
  2. dot product

If the minimal distance == 0, then we can say these two lines intersected

Intersection.LineLine in RhinoCommon

Intersection.LineLine

Example code I made:

1
2
3
4
5
6
7
8
9
10
11
using Rhino.Geometry.Intersect;
//
private void RunScript(Line lineA, Line lineB, double tolerance, bool finiteSegments, ref object A, ref object a, ref object b)
{
double lineA_a;
double lineB_b;
A = Intersection.LineLine(lineA, lineB, out lineA_a, out lineB_b, tolerance, finiteSegments);

a = lineA_a;
b = lineB_b;
}

IntersectinoLineLine_RhinoCommon

Also, there’s a componeny called Line|Line in grasshopper, we can directly use.
Line|Line