Choosing circle radius to fully fill a rectangle

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-05-23T09:33:04Z Indexed on 2010/05/23 9:40 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

Hi,

the pixman image library can draw radial color gradients between two circles. I'd like the radial gradient to fill a rectangular area defined by "width" and "height" completely. Now my question, how should I choose the radius of the outer circle?

My current parameters are the following:

A) inner circle (start of gradient)
center pointer of inner circle: (width*0.5|height*0.5)
radius of inner circle: 1
color: black

B) outer circle (end of gradient)
center pointer of outer circle: (width*0.5|height*0.5)
radius of outer circle: ???
color: white

How should I choose the radius of the outer circle to make sure that the outer circle will entirely fill my bounding rectangle defined by width*height. There shall be no empty areas in the corners, the area shall be completely covered by the circle. In other words, the bounding rectangle width,height must fit entirely into the outer circle. Choosing

outer_radius = max(width, height) * 0.5

as the radius for the outer circle is obviously not enough. It must be bigger, but how much bigger?

Thanks!

© Stack Overflow or respective owner

Related posts about math

Related posts about geometry