# Why won't my circles show?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

#### SpyKiller112

##### Guest
I'm trying to make it so that both of my circles' center points are 25 pixels away from each other. But, I'm not really sure how to do that. I know that the (x,y) coordinate you put in as a parameter for Ellipse2D.Double is at the top left of the bounding box, but really that's all I know.

Two_Circles class: http://fpaste.org/paste/6201
Two_Circles tester: http://fpaste.org/paste/6202

#### Chicon

Hi SpyKiller112,

Unfortunately, you have to apply the Pythagoras' theorem to find the coordinates of the circle center.
In your example, the coordinate of the first circle center (a, b) are :
a = 5 + sqrt((50*50)/2)
b = 10 + sqrt((50*50)/2)

Also, if D is the distance between 2 points (x1,y1) and (x2,y2), then :
(x1-x2)**2 + (y1-y2)**2 = D**2

#### SpyKiller112

##### Guest
Oh god, thanks a ton. I never would have thought of that! It would be so much easier if the coordinates referred to the center of the ellipse in the first place though.

#### Chicon

Hi SpyKiller112,

To solve the problem, you may add the following class in your program :
Code:
``````[SIZE=2]
package [COLOR=BLUE]your.package.name[/COLOR];

import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;

/**
*
* @author Chicon
*/
public abstract class Circle2D extends Ellipse2D {
public static class Double extends Ellipse2D implements Serializable {
public double x;
public double y;
public double height;
public double width;

public Double (double x, double y, double radius) {
this.x = x - v;
this.y = y - v;
}

@Override
public double getX() {
return this.x;
}

@Override
public double getY() {
return this.y;
}

@Override
public double getWidth() {
return this.width;
}

@Override
public double getHeight() {
return this.height;
}

@Override
public boolean isEmpty() {
return (width <= 0.0 || height <= 0.0);
}

@Override
public void setFrame(double x, double y, double w, double h) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
}

public Rectangle2D getBounds2D() {
return new Rectangle2D.Double(x, y, width, height);
}

}
}
}
[/SIZE]``````
Code:
``````[SIZE=2]
//recover Graphics2D
Graphics2D g2 = (Graphics2D) g;

//draws first circle
Circle2D.Double circle1 = new Circle2D.Double(40, 45, 50);
g2.draw(circle1);
[/SIZE]``````

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

As Seen On