distanceToPlane method

num? distanceToPlane(
  1. Plane plane
)

Implementation

num? distanceToPlane(Plane plane) {
  var 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;
  }

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

  // Return if the ray never intersects the plane

  return t >= 0 ? t : null;
}