intersectPlane method

Vector3? intersectPlane(
  1. Plane plane,
  2. Vector3 result
)

Performs a plane/plane intersection test and stores the intersection point to the given 3D vector. If no intersection is detected, null is returned.

Reference: Intersection of Two Planes in Real-Time Collision Detection by Christer Ericson (chapter 5.4.4)

Implementation

Vector3? intersectPlane(Plane plane, Vector3 result ) {
	// compute direction of intersection line
	d.crossVectors( normal, plane.normal );

	// if d is zero, the planes are parallel (and separated)
	// or coincident, so they’re not considered intersecting
	final denom = d.dot( d );
	if ( denom == 0 ) return null;

	// compute point on intersection line
	v1.copy( plane.normal ).multiplyScalar( constant );
	v2.copy( normal ).multiplyScalar( plane.constant );

	result.crossVectors( v1.sub( v2 ), d ).divideScalar( denom );

	return result;
}