From f35bad4c89977786664c87337460a014a6ec7b85 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 16 Aug 2024 08:41:49 +0100 Subject: [PATCH] posts: kd-tree-revisited: add presentation --- .../2024-08-17-kd-tree-revisited/index.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/content/posts/2024-08-17-kd-tree-revisited/index.md b/content/posts/2024-08-17-kd-tree-revisited/index.md index 137e2fd..5e5227f 100644 --- a/content/posts/2024-08-17-kd-tree-revisited/index.md +++ b/content/posts/2024-08-17-kd-tree-revisited/index.md @@ -20,3 +20,21 @@ neighbour search (i.e: the `closest` method) for the `KdTree` I implemented in [my previous post]({{< relref "../2024-08-10-kd-tree/index.md" >}}). + +## The improvement + +That post implemented the nearest neighbour search by keeping track of the +tree's boundaries (through `AABB`), and each of its sub-trees (through +`AABB.split`), and testing for the early exit condition by computing the +distance of the search's origin to each sub-tree's boundaries. + +Instead of _explicitly_ keeping track of each sub-tree's boundaries, we can +implicitly compute it when recursing down the tree. + +To check for the distance between the queried point and the splitting plane of +inner nodes: we simply need to project the origin onto that plane, thus giving +us a minimal bound on the distance of the points stored on the other side. + +This can be easily computed from the `axis` and `mid` values which are stored in +the inner nodes: to project the node on the plane we simply replace its +coordinate for this axis by `mid`.