>>I agree it's very simple in principle - sketch an example on a scrap of paper and you can easily work out the correct values. I'm just finding it difficult to come up with an (elegant) algorithm to get the program to do the same thing...
>
>This looks like a maximum problem for me, which is usually solved with derivatives.
>
>The basic approach is to calculate the area in terms of a single variable (several variables are possible, but more complicated). In this case, it could be a length.
>
>Then, calculate the derivative of this function. The derivative is a second function that gives the slope of the first function.
>
>This is relatively easy; the main problem, IMO, is the first part: get the expression for the area, in terms of some length.
>
>First, you must define your restrictions (if any): for instance, whether the lines of the rectangle should be horizontal and vertical, or not.
Simpler - because the restriction is there, the sides of the rectangle are parallel to coordinate axes. So, for the top side, its height is
if between(90, angle1, angle2)
top=radius + centerY
else
top=max(point1y, point2y)
endif
Now for other four sides, just rotate the whole logic by a right angle. There may be a little consideration over the right side - whether we have negative angles or we have angles of more then 360. IOW, what's the format of the given data.