选择圆半径以完全填充矩形
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
作为外圆的半径显然是不够的。它一定更大,但是大多少呢?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
圆的直径应该是矩形的对角线,您可以根据毕达哥拉斯定理轻松计算出来。即:
outer_radius = 0.5 * sqrt(宽度*宽度+高度*高度)
The diameter of the circle should be the diagonal of the rectangle, which you can easily calculate from Pythagoras' Theorem. ie:
outer_radius = 0.5 * sqrt(width * width + height * height)
这只是毕达哥拉斯:
或者更简单地说:
It's just Pythagoras:
or more simply:
您的问题不清楚,但也许您想要 sqrt(w^2 + h^2) / 2
这是从矩形中心到其角点的距离。
Your question isn't clear, but perhaps you want sqrt(w^2 + h^2) / 2
This is the distance from the center of the rectangle to its corner.
使用毕达哥拉斯:
Use Pythagoras:
您需要边长等于宽度/2 和高度/2 的直角三角形的斜边长度。或者,矩形对角线长度的 1/2。
(h/2 ^ 2 + w/2 ^ 2) 的平方根
或 1/2 * (h^2 + w^2) 的平方根
You want the length of the hypotenuse of a right triangle with sides equal width/2 and height/2. Alternatively, 1/2 the length of the diagonal of the rectangle.
Square root of (h/2 ^ 2 + w/2 ^ 2)
or 1/2 * Square root of (h^2 + w^2)
画一个小草图,并应用毕达哥拉斯定理:
[草图图像用于此处;链接已损坏,并且主机现在已被标记为恶意软件]
在代码中:
Make a little sketch, and apply Pythagoras's Theorem:
[sketch image used to go here; link is broken, and the host is flagged as malware now anyway]
In code: