- #1
Skaperen
- 80
- 0
I'm writing a little program for generating some images, and at one point I need to calculate how much of a circle is on either side of a straight line that bisects the circle. The line is always vertical so it is easy to get the value of how much of a horizontal line segment within the circle (e.g. the diameter of the circle) is on either side of the vertical line. Someone told me a simple formula for this many many years ago, but I was having trouble recalling what it was.
So I went to Google to try to track this down, basically searching for area of segment of a circle. But everything I found was based on knowing the angle of the circle sector that meets up with the segment of the circle. While that can be easily calculated, it doesn't make for a continuous formula that I can see (or at least that I can figure out how to code), since I have to handle segments less than 50% different than segments more than 50%. I wanted that formula that someone mentioned those many years ago.
Then suddenly I remembered that formula. Since I had at this point written some code to calculate the values based on the formula found via Google, I decided to verify things. What I found was that these two different formulas do NOT produce the same results, but they do cross at 0%, 50% and 100% segments, and in the worst case they are only about 6% apart.
The (now determined to be wrong) formula I remembered was based on the proportion of that horizontal line that is within the segment bisected by the vertical line. I'll call that p which has a range of [0..1].
area = sine( p * Pi / 2 )2 * Pi
Could there be some cases where this formula might have valid uses? Or was this person just guessing (and came up with something close)?
I wonder what kind of shape it would be that this formula would be correct for. I also wonder what kind of curve it is that the correct formula for the area (based on the area of the enclosed triangle minus the area of the sector) would have (close to, but not exactly the same as, sine squared).
So I went to Google to try to track this down, basically searching for area of segment of a circle. But everything I found was based on knowing the angle of the circle sector that meets up with the segment of the circle. While that can be easily calculated, it doesn't make for a continuous formula that I can see (or at least that I can figure out how to code), since I have to handle segments less than 50% different than segments more than 50%. I wanted that formula that someone mentioned those many years ago.
Then suddenly I remembered that formula. Since I had at this point written some code to calculate the values based on the formula found via Google, I decided to verify things. What I found was that these two different formulas do NOT produce the same results, but they do cross at 0%, 50% and 100% segments, and in the worst case they are only about 6% apart.
The (now determined to be wrong) formula I remembered was based on the proportion of that horizontal line that is within the segment bisected by the vertical line. I'll call that p which has a range of [0..1].
area = sine( p * Pi / 2 )2 * Pi
Could there be some cases where this formula might have valid uses? Or was this person just guessing (and came up with something close)?
I wonder what kind of shape it would be that this formula would be correct for. I also wonder what kind of curve it is that the correct formula for the area (based on the area of the enclosed triangle minus the area of the sector) would have (close to, but not exactly the same as, sine squared).