intersectPlane method

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

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

Implementation

Vector3? intersectPlane(Plane plane, Vector3 result ) {
	double t;

	final denominator = plane.normal.dot( direction );

	if ( denominator == 0 ) {
		if ( plane.distanceToPoint( origin ) == 0 ) {
			// ray is coplanar
			t = 0;
		}
      else {
			// ray is parallel, no intersection
			return null;
		}
	}
    else {
		t = - ( origin.dot( plane.normal ) + plane.constant ) / denominator;
	}

	// there is no intersection if t is negative

	return ( t >= 0 ) ? at( t, result ) : null;
}