Math 选择“圆半径”以完全填充矩形

Math 选择“圆半径”以完全填充矩形,math,trigonometry,geometry,Math,Trigonometry,Geometry,pixman图像库可以在两个圆之间绘制径向颜色渐变。我希望径向梯度完全填充由“宽度”和“高度”定义的矩形区域。现在我的问题是,我应该如何选择外圆的半径 我当前的参数如下: 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)

pixman图像库可以在两个圆之间绘制径向颜色渐变。我希望径向梯度完全填充由“宽度”和“高度”定义的矩形区域。现在我的问题是,我应该如何选择外圆的半径

我当前的参数如下:

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
我应该如何选择外圆的半径,以确保外圆将完全填充由宽度*高度定义的边界矩形。拐角处不得有空白区域,该区域应完全被圆圈覆盖。换句话说,边界矩形的宽度、高度必须完全适合外圆。选择

outer_radius = max(width, height) * 0.5
因为外圆的半径显然不够。它一定更大,但有多大

谢谢

就是毕达哥拉斯:

outer_radius = sqrt((width / 2)^2 + (height / 2)^2);
outer_radius = sqrt(width*width + height*height)*0.5
或者更简单地说:

outer_radius = sqrt(width^2 + height^2) / 2;

圆的直径应该是矩形的对角线,你可以根据毕达哥拉斯定理很容易地计算出来。即:


外半径=0.5*sqrt(宽*宽+高*高)

做一个小草图,应用毕达哥拉斯定理:

[素描图像用于显示在此处;链接已断开,主机现在仍被标记为恶意软件]

代码:

outer_radius = sqrt(0.25 * (width*width + height*height))

你的问题不清楚,但也许你想要sqrt(w^2+h^2)/2

这是从矩形中心到其角的距离。

使用毕达哥拉斯:

outer_radius = sqrt((width / 2)^2 + (height / 2)^2);
outer_radius = sqrt(width*width + height*height)*0.5

您需要一个边等于宽度/2和高度/2的直角三角形斜边的长度。或者,为矩形对角线长度的1/2。 (h/2^2+w/2^2)的平方根 或(h^2+w^2)的1/2*平方根