From 27d2e85573be14e28a17a031c09a157276ee1155 Mon Sep 17 00:00:00 2001 From: lee <205592689+jkhahe72-sh3@users.noreply.github.com> Date: Mon, 9 Mar 2026 18:12:33 +0100 Subject: [PATCH 1/4] Add point to plane distance using Hesse normal form Adds a function to compute the distance between a point and a plane in 3D using the Hesse normal form. --- geometry/point_to_plane_distance.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 geometry/point_to_plane_distance.py diff --git a/geometry/point_to_plane_distance.py b/geometry/point_to_plane_distance.py new file mode 100644 index 000000000000..b7c5adb28bad --- /dev/null +++ b/geometry/point_to_plane_distance.py @@ -0,0 +1,25 @@ +from math import sqrt + + +def point_to_plane_distance( + x: float, y: float, z: float, a: float, b: float, c: float, d: float +) -> float: + """ + Return the distance between a point (x, y, z) and the plane ax + by + cz + d = 0 using the Hesse normal form. + + Reference: + https://en.wikipedia.org/wiki/Hesse_normal_form + + >>> point_to_plane_distance(1, 2, 3, 1, 0, 0, -1) + 0.0 + >>> point_to_plane_distance(3, 2, 1, 1, 0, 0, -1) + 2.0 + >>> point_to_plane_distance(1, 2, 3, 0, 0, 0, 4) + Traceback (most recent call last): + ... + ValueError: Normal vector cannot be zero. + """ + if a == 0 and b == 0 and c == 0: + raise ValueError("Normal vector cannot be zero.") + + return abs(a * x + b * y + c * z + d) / sqrt(a**2 + b**2 + c**2) \ No newline at end of file From b0936781ce23e7776f762de0ca815b95c2e05d40 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:26:49 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- geometry/point_to_plane_distance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geometry/point_to_plane_distance.py b/geometry/point_to_plane_distance.py index b7c5adb28bad..1c9106f78ed6 100644 --- a/geometry/point_to_plane_distance.py +++ b/geometry/point_to_plane_distance.py @@ -21,5 +21,5 @@ def point_to_plane_distance( """ if a == 0 and b == 0 and c == 0: raise ValueError("Normal vector cannot be zero.") - - return abs(a * x + b * y + c * z + d) / sqrt(a**2 + b**2 + c**2) \ No newline at end of file + + return abs(a * x + b * y + c * z + d) / sqrt(a**2 + b**2 + c**2) From 710a359203a2d1e176975146856836eca5d922b3 Mon Sep 17 00:00:00 2001 From: lee <205592689+jkhahe72-sh3@users.noreply.github.com> Date: Mon, 9 Mar 2026 18:32:58 +0100 Subject: [PATCH 3/4] Fix line length in docstring --- geometry/point_to_plane_distance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/geometry/point_to_plane_distance.py b/geometry/point_to_plane_distance.py index b7c5adb28bad..35ab8c35a00b 100644 --- a/geometry/point_to_plane_distance.py +++ b/geometry/point_to_plane_distance.py @@ -5,7 +5,8 @@ def point_to_plane_distance( x: float, y: float, z: float, a: float, b: float, c: float, d: float ) -> float: """ - Return the distance between a point (x, y, z) and the plane ax + by + cz + d = 0 using the Hesse normal form. + Return the distance between a point (x, y, z) and the plane + ax + by + cz + d = 0 using the Hesse normal form. Reference: https://en.wikipedia.org/wiki/Hesse_normal_form From 204ba41bb092ad58fd3139e77fcd863326668619 Mon Sep 17 00:00:00 2001 From: lee <205592689+jkhahe72-sh3@users.noreply.github.com> Date: Mon, 9 Mar 2026 18:57:34 +0100 Subject: [PATCH 4/4] Use descriptive parameter names --- geometry/point_to_plane_distance.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/geometry/point_to_plane_distance.py b/geometry/point_to_plane_distance.py index 26a3cca7a2fd..6969803033d6 100644 --- a/geometry/point_to_plane_distance.py +++ b/geometry/point_to_plane_distance.py @@ -2,7 +2,13 @@ def point_to_plane_distance( - x: float, y: float, z: float, a: float, b: float, c: float, d: float + point_x: float, + point_y: float, + point_z: float, + normal_x: float, + normal_y: float, + normal_z: float, + plane_constant: float ) -> float: """ Return the distance between a point (x, y, z) and the plane @@ -20,7 +26,12 @@ def point_to_plane_distance( ... ValueError: Normal vector cannot be zero. """ - if a == 0 and b == 0 and c == 0: + if normal_x == 0 and normal_y == 0 and normal_z == 0: raise ValueError("Normal vector cannot be zero.") - return abs(a * x + b * y + c * z + d) / sqrt(a**2 + b**2 + c**2) + return abs( + normal_x * point_x + + normal_y * point_y + + normal_z * point_z + + plane_constant + ) / sqrt(normal_x**2 + normal_y**2 + normal_z**2)