Mondrian Subdivision Through Points

I have a python script which does a mondrian subdivision. This is where an initial rectangle is split into two or more rectangles - then those rectangles are split into two or more rectangles, etc. Right now, the splits happen at random points between parameters set it grasshopper. However, I would like the splits to happen through a set of points which are already determined. Can someone point me in the right direction on how I might do this because I’m new to Python. I read the RhinoPythonPrimer over the weekend (which was well written and funny) but I’m still lost. I’ve attached the file for clarity.

Mondrian Split Through Points.3dm (681.7 KB) Mondrian Split Through (8.0 KB)

Hi @neno_videnovic,

I believe what you’re looking for is the quadtree algorithm, a two-dimensional analog of the three-dimensional octree. It’s a tree data structure for faster proximity and neighbourhood searches, but it can also be perverted for graphical uses. :wink:
It’s already implemented in Grasshopper, but if you want to code it yourself in Python, I’d suggest you take a look at Shiffman’s video series (part 1, part 2). He usually programs in Processing or nowadays P5.js. but explains everything quite well, and it should be straightforward to translate to GHPython.