I am trying to draw circles in java as shown in the GeoGebra image. There is one drawback: it won't let me put them together. Is there any way to put it like in the picture? Or am I putting some data wrong?
Attached image in geogebra and in java.
DRAWING CLASS
package ejemplografica;
import java.awt.Color;
import java.awt.Graphics;
public class Dibujo {
public static void lugar( Graphics g, int x,int y, int ancho, int alto, boolean t)
{
g.setColor(Color.GREEN);
g.fill3DRect(x, y, ancho, alto, t);
}
public static void aspersor(Graphics g, int x, int y, int ancho, int alto)
{
g.setColor(Color.BLUE);
g.fillOval(x, y, ancho, alto);
}
}
GRAPHIC FORM
private void CuadradoMouseClicked(java.awt.event.MouseEvent evt) {
Dibujo.lugar(mainPanel.getGraphics(), 100, 100, 100, 90, false);
Dibujo.aspersor(mainPanel.getGraphics(), 85, 85, 30, 30);
Dibujo.aspersor(mainPanel.getGraphics(), 85, 85+30, 30, 30);
Dibujo.aspersor(mainPanel.getGraphics(), 85, 85+30*2, 30, 30);
Dibujo.aspersor(mainPanel.getGraphics(), 85, 85+30*3, 30, 30);}
private void Cuadrado1ActionPerformed(java.awt.event.ActionEvent evt) {
repaint();
}
Look at the following image:
Your case is the one on the right. You are inscribing a square in a circle. If you pay attention, the side of the square measures less than the diameter of the circle, so it is smaller and slightly offset.
What you have to do is inscribe the circle in a square (left). The diameter is equal to the side of the square. Do the measurements again but with this square.
That's the downside with every circle.
By the way, you may be more interested in using the function
fillRect
thatfill3DRect