main/src/georegression/metric/Intersection3D_F64.java
public static int intersectConvex(FastQueue<Point3D_F64> polygon,
									  LineParametric3D_F64 line , Point3D_F64 output,
									  Vector3D_F64 n, Vector3D_F64 u, Vector3D_F64 v, Vector3D_F64 w0) {
		if( polygon.size < 3 )
			throw new IllegalArgumentException("There must be 3 or more points");

		double r, a, b;              // params to calc ray-plane intersect

		Point3D_F64 v0 = polygon.get(0);
		Point3D_F64 v1 = polygon.get(1);
		Point3D_F64 v2 = polygon.get(2);

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

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

		Vector3D_F64 dir = line.slope;
		w0.minus(line.p,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;

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

		// See if it's inside any of the triangles
		for (int i = 2; i < polygon.size; i++) {
			// is I inside T?
			if (containedPlane(v0, output, u, v, w0)) {
				if (r >= 0)
					return 1;
				else
					return 3;
			}

			if (i < polygon.size - 1) {
				u.minus(polygon.get(i), v0);
				v.minus(polygon.get(i+1), v0);
			}
		}
		return 0;
	}
public static int intersectConvex(FastQueue<Point3D_F64> polygon,
									  LineParametric3D_F64 line , Point3D_F64 output,
									  Vector3D_F64 n, Vector3D_F64 u, Vector3D_F64 v, Vector3D_F64 w0) {
		if( polygon.size < 3 )
			throw new IllegalArgumentException("There must be 3 or more points");

		double r, a, b;              // params to calc ray-plane intersect

		Point3D_F64 v0 = polygon.get(0);
		Point3D_F64 v1 = polygon.get(1);
		Point3D_F64 v2 = polygon.get(2);

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

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

		Vector3D_F64 dir = line.slope;
		w0.minus(line.p,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;

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

		// See if it's inside any of the triangles
		for (int i = 2; i < polygon.size; i++) {
			// is I inside T?
			if (containedPlane(v0, output, u, v, w0)) {
				if (r >= 0)
					return 1;
				else
					return 3;
			}

			if (i < polygon.size - 1) {
				u.minus(polygon.get(i), v0);
				v.minus(polygon.get(i+1), v0);
			}
		}
		return 0;
	}
public static int intersectConvex ( FastQueue < Point3D_F64 > polygon , LineParametric3D_F64 line , Point3D_F64 output , Vector3D_F64 n , Vector3D_F64 u , Vector3D_F64 v , Vector3D_F64 w0 ) { if ( polygon . size < 3 ) throw new IllegalArgumentException ( "There must be 3 or more points" ) ; double r , a , b ; // params to calc ray-plane intersect Point3D_F64 v0 = polygon . get ( 0 ) ; Point3D_F64 v1 = polygon . get ( 1 ) ; Point3D_F64 v2 = polygon . get ( 2 ) ; // get triangle edge vectors and plane normal u . minus ( v1 , v0 ) ; // NOTE: these could be precomputed v . minus ( v2 , v0 ) ; n . cross ( u , v ) ; if ( n . normSq ( ) == 0 ) // triangle is degenerate return - 1 ; // do not deal with this case Vector3D_F64 dir = line . slope ; w0 . minus ( line . p , 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 ; // intersect point of ray and plane output . x = line . p . x + r * dir . x ; output . y = line . p . y + r * dir . y ; output . z = line . p . z + r * dir . z ; // See if it's inside any of the triangles for ( int i = 2 ; i < polygon . size ; i ++ ) { // is I inside T? if ( containedPlane ( v0 , output , u , v , w0 ) ) { if ( r >= 0 ) return 1 ; else return 3 ; } if ( i < polygon . size - 1 ) { u . minus ( polygon . get ( i ) , v0 ) ; v . minus ( polygon . get ( i + 1 ) , v0 ) ; } } return 0 ; }
Detects if a 2D convex polygon that has been moved into a 3D world is intersected by the 3D line.
<pre>
Transformation:
1) Each 2D point is converted into 3D: X=(x,y,0)
2) X' = R*X + T, where (R,T) are a rigid body transform from poly to world frames
</pre>

@param polygon (Input) Convex polygon. All points must lie on a plane.
@param line (Input) Line.
@param output (Output) Point of intersection (if any)
@param n (internal use)
@param u (internal use)
@param v (internal use)
@param w0 (internal use)
@return <ul style="list-style-type:none">
<li>-1 = triangle is degenerate (a segment or point)</li>
<li>0 =  disjoint (no intersect)</li>
<li>1 =  intersect in unique point. Positive direction or zero</li>
<li>2 =  are in the same plane</li>
<li>3 =  intersect in unique point. Negative direction</li>
</ul>
Detects if a 2D convex polygon that has been moved into a 3D world is intersected by the 3D line . <pre > Transformation : 1 ) Each 2D point is converted into 3D : X = ( x y 0 ) 2 ) X = R * X + T where ( R T ) are a rigid body transform from poly to world frames < / pre >