I'm writing a program where I need to divide a large rectangle into small pieces, no constraint on being exactly equally sized or exactly rectangle(they can be a square as well) and even if they protrude out of the larger rectangle a little, it'll be fine. I know how to divide a rectangle into some number of rectangles, but my current situation is making it difficult to visualize how many rectangles should I divide it into.
Let me explain the scenario - I've been given a large rectangle with
n number of uniformly distributed points inside it and I've to make smaller rectangles so that each rectangle has ~10^3-10^4 points in it. The
n can vary easily from 10^5 - 10^8 and even above. My idea is to cluster those points into smaller rectangles so that I don't have to compare all points linearly and just compare their bounding rectangles to the geometric figure. So in earlier case, I would be comparing millions of points for each geometric figure, now I would be comparing much much less number of bounding rectangles.
For now I've hardcoded the values eg. 1000 smaller rectangles for 10^6 number of points and like that for 10^7 and 10^8. But it has a disadvantage that instead of calculating for continuous range, I'm hard coding for discrete range which does not work for 5000000 number of points or any such in middle. Also, they are usually made into thin strips which makes them very hard to fall completely within the geometric shape I'm comparing with.
I hope I've explained it clearly, but I'll provide a TLDR;
Given a rectangle with
n number of points uniformly distributed inside it, split that rectangle into smalle rectangles with 10^3-10^4 number of points in each of them.
Also, the naive solution like dividing into very slim strips does not work for me because then most strips only intersect with geometric figure rather than falling within it completely, it would be preferable for an algorithm/function to make somewhat both axis uniform boxes.
________ ________ | | | | | <-- slim strips | | | <-- much better | | | | | |---|---| |_|_|_|_| |___|___|