intersectionWithLine method

Point? intersectionWithLine(
  1. Line line
)

Finds the intersection point between a line and the plane. If the line is parallel to the plane and doesn't intersect, it returns null.

Implementation

Point? intersectionWithLine(Line line) {
  Point lineVector = line.point2 - line.point1;
  double denominator = normal.dot(lineVector.toVector());

  if (denominator.abs() < 1e-10) {
    // The line is parallel to the plane
    return null;
  }

  double t =
      normal.dot(point.toVector() - line.point1.toVector()) / denominator;
  return line.point1 + lineVector.scale(t);
}