CS333 Lab S-1:
Supplement to RPC Lab
Nearest Point Algorithm
Problem:
Given a table of points (Table), radius of consideration (Radius), and a target point (TargetPnt), find a point in the table that is
closest to the target point (ClosestPnt).
Strategy:
Only points inside the radius of consideration are candidates for the closest point.
Sort the table by X field, and find a set of points (XRange) in the table such that
Abs(Pnt.X - TargetPnt.X) < Radius.
Sort the table by Y field, and similarly find a set of points (YRange) that are less than Radius away along
the Y axis.
Find intersection of XRange and YRange sets. For each point in the intersection, calculate its distance
from the TargetPnt. ClosestPnt is the one with the smallest distance.
Implementation Hints:
Sorting with respect to X and Y can be done once at the time data is loaded in the table.
Create two index tables where each element of the table is an index into the data table. Sort one index
table by the X field, and the other one by the Y field. When finding the closest point, use these two index
tables, instead of resorting the data table.
Back to RPC lab description