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

发布于 2024-09-02 18:47:28 字数 595 浏览 9 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

染年凉城似染瑾 2024-09-09 18:47:28

圆的直径应该是矩形的对角线,您可以根据毕达哥拉斯定理轻松计算出来。即:

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)

浪荡不羁 2024-09-09 18:47:28

这只是毕达哥拉斯:

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

或者更简单地说:

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

It's just Pythagoras:

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

or more simply:

outer_radius = sqrt(width^2 + height^2) / 2;
裸钻 2024-09-09 18:47:28

您的问题不清楚,但也许您想要 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.

冰雪梦之恋 2024-09-09 18:47:28

使用毕达哥拉斯:

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

Use Pythagoras:

outer_radius = sqrt(width*width + height*height)*0.5
太阳男子 2024-09-09 18:47:28

您需要边长等于宽度/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)

谈情不如逗狗 2024-09-09 18:47:28

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

[草图图像用于此处;链接已损坏,并且主机现在已被标记为恶意软件]

在代码中:

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

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:

outer_radius = sqrt(0.25 * (width*width + height*height))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文