distanceToPlane method

double? distanceToPlane(
  1. Plane plane
)

Implementation

double? distanceToPlane(Plane plane) {
  final denominator = plane.normal.dot(direction);

  if (denominator == 0) {
    // line is coplanar, return origin
    if (plane.distanceToPoint(origin) == 0) {
      return 0;
    }

    // Null is preferable to undefined since undefined means.... it is undefined

    return null;
  }

  final t = -(origin.dot(plane.normal) + plane.constant) / denominator;

  // Return if the ray never intersects the plane

  return t >= 0 ? t : null;
}