Exercise: Hausdorff distance

Task: Given two collections $P$ and $Q$ of points in the plane, compute the Hausdorff distance between sets $P$ and $Q$. The Hausdorff distance between $P$ and $Q$, denoted here by $H(P, Q)$, is defined as follows. Let

$$ h(P, Q) = \max_{p \in P} \min_{q \in Q} \| p - q\| $$

where, for any $p \in \mathbb{R}^2$, the notation $\| p \|$ denotes the Euclidean distance $\sqrt{p\cdot p}$. Using this, the Hausdorff distance is defined by $$ H(P, Q) = \max \big[ h(P, Q),\; h(Q, P) \big]. $$

In [1]:
import numpy as np
P = np.random.rand(5, 2)
Q = np.random.rand(7, 2)