计算“饼图段”面积的边界点 和“子区域”

发布于 2024-07-22 07:28:19 字数 1066 浏览 10 评论 0原文

背景

我最近正在使用 GDI+ 绘制一个“光盘”,显示 360 度的全面颜色变化。 (我挖了一些HSL到RGB的代码来循环HSL(1,1,1) -> HSL(360,1,1))

关于光盘,我首先使用上面的方法画了一个完整的实心圆,然后中心上的第二个灰色圆圈给出以下

alt text

所以这一切都很好..但我意识到 GDI+ 使我们免受通过 FillPie 方法进行的许多棘手的匹配。 此外,FillPie 要求您提供饼图的边界矩形,而不是半径长度。 它还执行完整的段填充,并且不允许您仅指定该段的一部分。

问题:

任何人都可以向我指出一些数学函数的方向,或者对我需要什么论坛来计算面积和面积给出任何解释吗? 给出以下“绿色填充区域”的绘图点:

Point `c` - an x,y co-ordinate
Angle `A` - an angle from horizontal
Angle `B  - an angle from horizontal where `B` - `A` == the sweep angle
Length `r` - a distance from `c`
Length `r2` - a distance from `c` where `r2` - `r` == the `height` of the segment to be filled.

alt text

数学源的链接很好但我已经快速谷歌& 看看 Wolfram Math 可以找到我正在寻找的东西。 另外,如果有某种方法可以生成可以作为 Point[] 传递给 Graphics.FillPolygon 的边界 (x,y) co-or 序列,那也很酷。

Background:

I was recently playing around with GDI+ to draw a "Disc" displaying a sweeping color change through 360 degrees. (I dug up some HSL to RGB code to loop through HSL(1,1,1) -> HSL(360,1,1))

Regarding the disc, I first drew a full solid circle using the above, and then a second circle in Grey over the center to give the following

alt text

So this is all fine... but I realised that GDI+ is insulating us from a lot of the tricky match that's going on here by way of the FillPie method. Also, FillPie requires you to supply a bounding rectangle for the pie as opposed to a Radius Length. It also does a full segment fill and doesnt allow you to specify a part of that segment only.

Question:

Can anyone point me in the direction of some Math functions or give any explanation on what forumla I would need to calculate the area & plot points of the following "Green Filled Area" given:

Point `c` - an x,y co-ordinate
Angle `A` - an angle from horizontal
Angle `B  - an angle from horizontal where `B` - `A` == the sweep angle
Length `r` - a distance from `c`
Length `r2` - a distance from `c` where `r2` - `r` == the `height` of the segment to be filled.

alt text

Links to Math sources are fine but I've had a quick google & look at Wolfram Math and could find what I was looking for. Also, if there was some way to generate a sequence of bounding (x,y) co-or's that could be passed as a Point[] to Graphics.FillPolygon, that'd be cool too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

梦明 2024-07-29 07:28:19

该面积是外圆盘部分和内圆盘部分的差。 圆盘部分的面积与扫角成正比:

area = (b-a)*((r+r2)^2-r^2)/2

ab 必须以弧度表示。
对于ba = 2*Piarea = Pi*(r+r2)^2 - Pi*r^2是外盘和内盘面积之差。

在内/外圆上生成点。

x = cx + r * cos(t)     /     x = cx + (r+r2) * cos(t)
y = cy + r * sin(t)     /     y = cy + (r+r2) * sin(t)

您可以使用其中 tab 变化的方式

The area is the difference of the outer and inner disc parts. The area of a disc part is proportional to the angle sweep:

area = (b-a)*((r+r2)^2-r^2)/2

a and b must be expressed in radians.
For b-a = 2*Pi, area = Pi*(r+r2)^2 - Pi*r^2 is the difference of the areas of the outer and inner discs.

You can generate points on the inner / outer circle using

x = cx + r * cos(t)     /     x = cx + (r+r2) * cos(t)
y = cy + r * sin(t)     /     y = cy + (r+r2) * sin(t)

Where t varies from a to b.

木槿暧夏七纪年 2024-07-29 07:28:19

希望这可以帮助。 第二部分提供了计算圆扇形面积的方法

http://www.wikihow.com/Calculate-the-Area-of-a-Circle

Hope this helps. The second part provides a method for calculating the area of a sector of a circle

http://www.wikihow.com/Calculate-the-Area-of-a-Circle

峩卟喜欢 2024-07-29 07:28:19

圆弧的面积就是圆弧的角度(以弧度为单位)乘以半径。 所以绿色圆圈的面积显然是:

(B-A) * r2

The area of a segment of a circle is simply the angle of the arc (in radians) times the radius. So the area of the green circle is obviously:

(B-A) * r2
阳光①夏 2024-07-29 07:28:19

您需要画线(此伪代码):

for aa from A to B
  set color to required color // you could use aa in an equation with HSL to get something like your sample
  x1=r*cos(aa)+x
  y1=r*sin(aa)+y
  x2=r1*cos(aa)+x
  y2=r1*sin(aa)+y
  draw line between (x1,y1) and (x2,y2)

对于足够小的角度增量和足够小的半径,这应该没问题。

您要寻找的点是每个角度 aa 的 (x1,y1) 和 (x2,y2)

You need to draw lines (this pseudo code):

for aa from A to B
  set color to required color // you could use aa in an equation with HSL to get something like your sample
  x1=r*cos(aa)+x
  y1=r*sin(aa)+y
  x2=r1*cos(aa)+x
  y2=r1*sin(aa)+y
  draw line between (x1,y1) and (x2,y2)

for a small-enough increment in the angles, and small-enough radii, this should be OK.

The points you're looking for are (x1,y1) and (x2,y2) for each angle aa

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