Issues

Issue #35 new

Line3D - Line3D Intersection

Victor Vina
created an issue

Hi Karsten,

I'm trying to write a general-purpose function to check whether two 3D lines intersect each other. I think I'm missing something trivial here. I implemented it with closestLineTo method of LineIntersection class. I am checking 3 things:

LineIntersection.Type (INTERSECTING) Length of closest line (should be 0 for intersecting lines). coefficients (in the Javadocs it mentions they should be between 0 and 1, but somehow the function works if the second coefficient is between -1 and 0.

Right now the function works except for overlapping, parallel lines. Can you please suggest an alternative approach, or is this the best way to go about this?

Thanks in advance.

{{{

!java

boolean checkLineIntersection(Line3D a, Line3D b) { Line3D.LineIntersection closestLine = a.closestLineTo(b); float[] coefficients = closestLine.getCoefficients(); if (closestLine.getType().equals(Line3D.LineIntersection.Type.valueOf("INTERSECTING"))) { float closestLineLength = closestLine.getLength(); if (closestLineLength == 0 && coefficients[0] > 0 && coefficients[0] < 1 && coefficients[1] > -1 && coefficients[1] < 0) { Line3D i = closestLine.getLine(); Vec3D p = i.a; return true; } else { return false; } } else { return false; } } }}}

Comments (0)

  1. Log in to comment