# How to calculate the center of a circle inscribed in a circle sector

I’m having trouble figuring out how to set “r” so that the small circle is inscribed within the sector. The number of sectors will vary. I would also appreciate help with math to calculate the points where the small circles will be tangent to the sector sides. Any help would be appreciated

``````PVector c;
float d, R, r, n, sectorAngle, offset;
void setup() {
size(400,600);
c = new PVector(width/2, height/2);
d = 300;
R = d/2;
r = R * 0.8; // how to calculate "r" based on different values of "n"
n = 3;
sectorAngle = TWO_PI/n;
offset = -HALF_PI;
}
void draw() {
background(127);
strokeWeight(5);
stroke(0);
fill(175);

pushMatrix();
//
translate(c.x, c.y);
// the circle
ellipse(0, 0, d, d);
// the sector
for(int i = 0; i < n; i++) {
pushMatrix();
///
rotate(i*sectorAngle);
drawSector();
///
popMatrix();
}
// center point
strokeWeight(10);
stroke(0);
point(0, 0);
//
popMatrix();
}
void drawSector() {
PVector a = new PVector(R*cos(0+offset), R*sin(0+offset));
PVector b = new PVector(R*cos(sectorAngle+offset), R*sin(sectorAngle+offset));
PVector bisector = new PVector(R*cos(sectorAngle/2+offset), R*sin(sectorAngle/2+offset));
PVector incircleCenter = new PVector((R-r/2)*cos(sectorAngle/2+offset), (R-r/2)*sin(sectorAngle/2+offset));
// draw sector points
strokeWeight(20);
stroke(200,0,0);
point(a.x, a.y);
point(b.x, b.y);
// draw sector lines
strokeWeight(3);
stroke(200,0,0);
line(0, 0, a.x, a.y);
line(0, 0, b.x, b.y);
// draw sector angle bisector
strokeWeight(1);
stroke(0);
line(0, 0, bisector.x, bisector.y);
//draw incircle
noFill();
ellipse(incircleCenter.x, incircleCenter.y, r, r);
// incircle center point
strokeWeight(10);
stroke(0);
point(incircleCenter.x, incircleCenter.y);
}
``````
1 Like

sin(tau/2) = r/(R−r)

but i had to change the r thinking later in your code,
in draw ellipse use ( 2 * r )
in centerpoint use ( R - r )

``````// https://discourse.processing.org/t/how-to-calculate-the-center-of-a-circle-inscribed-in-a-circle-sector/13279
// say sin(tau/2) = r/(R-r)
// try to find r
// sin(tau/2) = 1/(R/r -1)
// R/r = 1/sin(tau/2) + 1
// r = R / (1/sin(tau/2) + 1 )

PVector c;
float d=300, R = d/2, r, n=2, sectorAngle=TWO_PI/n, offset = -HALF_PI;

void setup() {
size(400, 600);
c = new PVector(width/2, height/2);
r = R /(1/sin(sectorAngle/2) + 1 );
println("use key [+] [-]");
}

void draw() {
background(127);
strokeWeight(5);
stroke(0);
fill(175);

pushMatrix();
translate(c.x, c.y);
ellipse(0, 0, d, d);            // the circle
for (int i = 0; i < n; i++) {   // the sector
pushMatrix();
rotate(i*sectorAngle);
drawSector();
popMatrix();
}
strokeWeight(10);              // center point
stroke(0);
point(0, 0);
popMatrix();
}

void drawSector() {
PVector a = new PVector(R*cos(0+offset), R*sin(0+offset));
PVector b = new PVector(R*cos(sectorAngle+offset), R*sin(sectorAngle+offset));
PVector bisector = new PVector(R*cos(sectorAngle/2+offset), R*sin(sectorAngle/2+offset));
PVector incircleCenter = new PVector((R-r)*cos(sectorAngle/2+offset), (R-r)*sin(sectorAngle/2+offset));
// draw sector points
strokeWeight(20);
stroke(200, 0, 0);
point(a.x, a.y);
point(b.x, b.y);
// draw sector lines
strokeWeight(3);
stroke(200, 0, 0);
line(0, 0, a.x, a.y);
line(0, 0, b.x, b.y);
// draw sector angle bisector
strokeWeight(1);
stroke(0);
line(0, 0, bisector.x, bisector.y);
// incircle center point
strokeWeight(10);
stroke(0);
point(incircleCenter.x, incircleCenter.y);
//draw incircle
noFill();
strokeWeight(1);
ellipse(incircleCenter.x, incircleCenter.y, 2*r, 2*r);
}

void keyPressed() {
if ( key == '+' )         n++;
if ( key == '-' & n > 2 ) n--;
println("new n "+n);
sectorAngle=TWO_PI/n;
r = R /(1/sin(sectorAngle/2) + 1 );
}

``````

is that what you need?

2 Likes

Yes, that’s what I was trying for, thank you! I tried all kinds of ways to rearrange that equation, like a bear playing badminton.

Thanks for showing how to rearrange it to solve “r”

The Wolfram online rearranger widget says `r = (R sin(tau/2)) / (sin(tau/2) + 1)` but that didn’t work.

2 Likes

you can divide that by `sin(tau/2)`
and you get

r = R / ( 1 + 1/sin(tau/2) )

what is same like i used.

possibly because of the 2 problems i mentioned above,

in draw ellipse use ( 2 * r ) / you used ( r )
in centerpoint use ( R - r ) / you used ( R -r/2 )

1 Like