I need an algorithm to place a set of N rectangles inside a circle of radius R, so that they are scaled up to the biggest possible size that doesn't exceed the border of the circle. I'm still working on it so If I find the answer I'll post it here...
If I would do this I would probably do it through a binary search using a function testing whether the problem is solvable for a given N, R and rectangle_scale.
The test function should probably be something like:
testfunction(R, rectangle_scale)
The binary search would then be standard:
while(upperbound-lowerbound > limit) {
new_bound = (upperbound+lowerbound) / 2;
num_fit = testfunction(N, R, new_bound);
if(num_fit > N) {
upperbound = new_bound;
} else {
lowerbound = new_bound;
}
}
Ideally you would of course want to do this mathematically. If an approximation is fine for you, you could maybe do it through areas. A proximation would be (rectangle_area*scale*N = pi*R^2) => scale = scale = pi*R^2 / N / rectangle_area.
However, if you need accuracy I would only use the area approximation for setting the initial lower/upper bounds in an intelligent way.
Hope this helps!