Calculation of bounding points for the pie segment and subzone area

Background

I recently played with GDI + to draw a “Disc” showing a sharp color change of 360 degrees. (I dug up some HSL to the RGB code to go through HSL (1,1,1) -> HSL (360,1,1))

As for the disc, I first drew a full solid circle using the above and then a second circle in gray above the center to give the next

alt text

So, everything is in order ... but I realized that GDI + isolates us from the big difficult match that happens here using the method FillPie. It also FillPierequires that you provide a bounding box for the pie, not a radius. It also fills the entire segment and does not allow you to specify only part of this segment.

Question:

Can someone point me towards some mathematical functions or give some explanation on which forum I will need to calculate the area and plot points of the following "green filled zone":

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

The links to Math sources are great, but I had a quick google and look at Wolfram Math and I can find what I was looking for. Also, if there was a way to generate a sequence of bounding (x, y) co-or that could be passed as Point[]in Graphics.FillPolygon, that would be cool too.

+3
source share
4 answers

Area is the difference between the external and internal parts of the disk. The area of ​​the disk part is proportional to the sweep of the angle:

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

a b . b-a = 2*Pi, area = 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)

t a b.

+3

- ( ), . , , :

(B-A) * r2
0

( ):

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)

.

, , (x1, y1) (x2, y2) aa

0

Source: https://habr.com/ru/post/1709467/


All Articles