[Math] Equation for concentric circles

circlesgeometrylinear algebra

I want an equation for concentric circles. In following image I am trying to draw concentric circles in Java but as you can see these are messed up.

This is because their (x,y) coordinates (i.e. positions) are measured from the upper-left corner, but because of having different heights and widths both circles no longer remain concentric. So I need to know how much I should increment x and y for smaller circle. Can anyone provide some equation?

Following are the methods I am using to draw circles in Java:

    g.setColor( Color.YELLOW );
    g.fillOval( 10, 10, 300, 300 ); // x,y, width,height

    g.setColor( Color.CYAN );
    g.fillOval( 10, 10 , 200, 200 ); // x,y, width,height

enter image description here

Best Answer

As you can see in your picture, your two circles have different origins, but concentric circles must share the same origin. Specifically, the first circle has an origin of $(160,160)$ ($10 + 150$ radius) while the second circle has an origin of $(110,110)$ ($10 + 100$ radius). To equalize the two origins, simply add 50 to the $x$ and $y$ upper-left corner for the second circle:

g.setColor(Color.YELLOW);
g.fillOval(10, 10, 200, 200);

g.setColor(Color.CYAN);
g.fillOval(60, 60, 100, 100);

Here is another example with a generalized equation:

int origin = 160;
int diameter1 = 300;
int diameter2 = 200;
int diameter3 = 100;

g.setColor(Color.YELLOW);
g.fillOval((origin - (diameter1 / 2),
           (origin - (diameter1 / 2), diameter1, diameter1);

g.setColor(Color.CYAN);
g.fillOval((origin - (diameter2 / 2),
           (origin - (diameter2 / 2), diameter2, diameter2);

g.setColor(Color.MAGENTA);
g.fillOval((origin - (diameter3 / 2),
           (origin - (diameter3 / 2), diameter3, diameter3);