Spatial sorting: the gory details

<aside> ❓

Deadline is 2025-12-11@18:00

Late submission? 10% will be removed for each day that you are late (3 days max)

It’s worth 15% of the final mark

This is an individual assignment

</aside>

SCR-20251122-kjlq.png

SCR-20251122-kjnq.png


This assignment has two parts:

  1. Coding the Morton/Hilbert curve for a simple grid (as shown above) [7.5%]
  2. Sorting buildings in a dataset according to the Morton code [7.5%]

<aside> <img src="/icons/save_orange.svg" alt="/icons/save_orange.svg" width="40px" />

Help/starting code is in the /hw/02/ folder of the TUDelft GitLab repository of the course (you need to login with your NetID).

</aside>

Part 1: Morton curve for a grid

You have to add functions to the small Python *tkinter* application so that the Morton curve is correctly drawn, for the order=2, 3, 4, and 5 (the order of the curve is the number of bits necessary to store the i or j coordinate, below the order=3). (Once you get the logic, your code should draw the curve of any order). The function to complete is compute_morton(self) , but you are allowed (and expected) to add other functions to the unit interface.py.

The Morton code is mandatory and what will be marked, but if you feel like it, you can try the Hilbert curve too.

⚠️ It is important that the Morton curve is drawn like the one below: the start of the curve is at (0, 0) with a coordinate reference with the origin at the bottom-left. The order of each curve is a (recursive) “N”.

If you want to draw the Hilbert curve, try to make it look like the one above, which for order=1 starts at (0, 0) with a “cup” (inverted “U”).

SCR-20251104-onnk.png

Order=1 of both curves should be like as follows:

SCR-20251122-kkox.png

SCR-20251122-kkqv.png

The code given already takes care of scaling and drawing the curve for both the Morton and the Hilbert curves. You only need to provide in order the (i,j)-tuples for a given order in the self.lsMorton array and the application will convert those (i,j)-tuples to the appropriate (x,y)-coordinates (real-world coordinates of the canvas, which is 800x800) and draw the curve. Switching to a different order should work automatically because the variable self.lsMorton gets re-initialised when the order of the curve is modified.


Part 2: Sorting buildings in a dataset