2
votes

I'm trying to divide a circle into 2 segments based on 2 percentages. Like a pie chart but creating the segments with a single vertical slice. I've found this formula for area, but haven't been able to solve for C (central angle) when I know the radius and area:

(R(squared) / 2) * ( ((pi/180)* C) - sin(C) )

Once I've got C I can use cos, tan and R(radius) to find my x and y points on the circle.

At first I thought I could simply multiply 180 * (smallerPercent / 50), but I realized that's a 'no'.

2

2 Answers

1
votes

This is a good application for Newton's method. The following C program can easily be modified to solve the problem. You can change it to calculate the desired area as a percentage of the area of the circle, or calculate the desired area separately and enter it.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double chordangle(double r,double a)
{
  double x = a/2.0;
  do{
    x = ((x * r * r / M_PI) - (sin(x) * r * r / 2.0) - a ) / 
      (r * r / M_PI - (r * r / 2.0) * cos(x));
  }while(((x * r * r / M_PI) - (sin(x) * r * r / 2.0 ) - a) > 1e-11);
  return x;
}

int main()
{
  double a,r;
  printf("Enter radius: ");
  if(scanf("%lf",&r)!=1)
    {
  printf("You must enter a number.\n");
  exit(1);
    }
  printf("Enter desired area of slice: ");
  if(scanf("%lf",&a)!=1)
    {
      printf("You must enter a number.\n");
      exit(1);
    }
  printf("The angle in radians is %lf.\n",chordangle(r,a));
  printf("The angle in degrees is %lf.\n",chordangle(r,a)*180.0/M_PI);      
  return 0;
}
0
votes

I have updated this answer (the original is at the very bottom).

You already know the radius of the circle, it's area (PI * r squared) and the area of the segment you are trying to construct (smallerPercentage / 100 * areaOfCircle).

If I understand the problem correctly, there is no formula to work out the angle that is required to create a segment of a given area and radius.

enter image description here

However all is not lost.

If you knew the angle you could also work out the area with the formula you already have. A = 0.5 * r squared * ( ((PI/180) * Θ) - sin(Θ)) where Θ is the angle.

So, the only solution is to start making methodical guesses at Θ and see if the area calculated matches what you are expecting (within a certain tolerance).

And given that the percentage will be less than 50 (and greater than 0) then: 0 < angle < 180.

So, I would make my first guess at 90 degrees. If the area is too big guess again at 45, too small try 135. Keep halving the size each time and add or subtract it from the previous angle. Keep narrowing it down until you get an area that is within a tolerance of the area you are expecting. Less than 10 guesses should get you there.

I think this is called the "1/4 Tank dipstick problem": see: http://mathforum.org/library/drmath/view/61752.html

I hope this helps.


This was my original answer, before I properly understood what you were trying to do:

I'm not sure I fully understand what you are trying to achieve, but you can work out the angles you want (in degrees) like this:

smallAngle = 360/100 * smallerPercentage;
largeAngle = 360 - smallAngle;

And you can always multiply degrees by (PI/180) to get radians.