main/src/georegression/metric/Intersection3D_F64.java
public static int intersect(Triangle3D_F64 T , LineSegment3D_F64 R , Point3D_F64 output ,
								Vector3D_F64 u , Vector3D_F64 v , Vector3D_F64 n,
								Vector3D_F64 dir , Vector3D_F64 w0 ) {
		double r, a, b;              // params to calc ray-plane intersect

		// get triangle edge vectors and plane normal
		u.minus(T.v1,T.v0);   // NOTE: these could be precomputed
		v.minus(T.v2,T.v0);
		n.cross(u,v);

		if ( n.normSq() == 0 )        // triangle is degenerate
			return -1;                  // do not deal with this case

		dir.minus(R.b,R.a);             // ray direction vector
		w0.minus(R.a,T.v0);
		a = -n.dot(w0);
		b = n.dot(dir);
		if (Math.abs(b) < GrlConstants.EPS) { // ray is  parallel to triangle plane
			if (a == 0)                       // ray lies in triangle plane
				return 2;
			else return 0;                    // ray disjoint from plane
		}

		// get intersect point of ray with triangle plane
		r = a / b;
		if (r < 0.0)                    // ray goes away from triangle
			return 0;                   // => no intersect
		else if( r > 1.0 )              // is past the end of the line segment
			return 0;

		// intersect point of ray and plane
		output.x = R.a.x + r*dir.x;
		output.y = R.a.y + r*dir.y;
		output.z = R.a.z + r*dir.z;

		// is I inside T?
		if( containedPlane(T.v0,output,u,v,w0)) {
			return 1;
		} else {
			return 0;
		}
	}
public static int intersect(Triangle3D_F64 T , LineSegment3D_F64 R , Point3D_F64 output ,
								Vector3D_F64 u , Vector3D_F64 v , Vector3D_F64 n,
								Vector3D_F64 dir , Vector3D_F64 w0 ) {
		double r, a, b;              // params to calc ray-plane intersect

		// get triangle edge vectors and plane normal
		u.minus(T.v1,T.v0);   // NOTE: these could be precomputed
		v.minus(T.v2,T.v0);
		n.cross(u,v);

		if ( n.normSq() == 0 )        // triangle is degenerate
			return -1;                  // do not deal with this case

		dir.minus(R.b,R.a);             // ray direction vector
		w0.minus(R.a,T.v0);
		a = -n.dot(w0);
		b = n.dot(dir);
		if (Math.abs(b) < GrlConstants.EPS) { // ray is  parallel to triangle plane
			if (a == 0)                       // ray lies in triangle plane
				return 2;
			else return 0;                    // ray disjoint from plane
		}

		// get intersect point of ray with triangle plane
		r = a / b;
		if (r < 0.0)                    // ray goes away from triangle
			return 0;                   // => no intersect
		else if( r > 1.0 )              // is past the end of the line segment
			return 0;

		// intersect point of ray and plane
		output.x = R.a.x + r*dir.x;
		output.y = R.a.y + r*dir.y;
		output.z = R.a.z + r*dir.z;

		// is I inside T?
		if( containedPlane(T.v0,output,u,v,w0)) {
			return 1;
		} else {
			return 0;
		}
	}
<p>Finds the intersection between a 3D triangle and a line-segment.  Code ported from [1].  Internal
working variables are provided in this interface to reduce memory creation/destruction.</p>

<p>
[1] http://geomalgorithms.com/a06-_intersect-2.html
</p>

@param T (Input) Triangle in 3D space
@param R (Input) Line segment in 3D space.
@param output (Output) Storage for the intersection, if there is one
@param u   (internal use) triangle vectors
@param v   (internal use) triangle vectors
@param n   (internal use) triangle vectors
@param dir (internal use) ray vector
@param w0  (internal use) ray vector
@return -1 = triangle is degenerate (a segment or point)
0 =  disjoint (no intersect)
1 =  intersect in unique point I1
2 =  are in the same plane