//KeplerTriangle.java //inscribed and circumscribed circle of equilateral triangle //inscribed circle radius r, then triangle side is 2r*sqrt(3) and area is 3r*sqrt(3) import java.awt.*; import javax.swing.*; public class KeplerTriangle extends JApplet { int r; int stopN; public void init() { String input; input = JOptionPane.showInputDialog("Radius of inscribed circle","50"); r = Integer.parseInt(input); input = JOptionPane.showInputDialog("Number of iterations","1"); stopN = Integer.parseInt(input); } public void paint ( Graphics g ) { int w = getWidth(); int h = getHeight(); int xc = w/2; int yc = h/2; for (int n=1; n<=stopN; n++) { g.drawOval(xc-r*n,yc-r*n, 2*r*n,2*r*n); //inscribed circle g.drawLine(xc,yc-2*r*n, (int)(xc-r*Math.sqrt(3)*n),yc+r*n); g.drawLine((int)(xc-r*Math.sqrt(3)*n),yc+r*n, (int)(xc+r*Math.sqrt(3)*n),yc+r*n); g.drawLine((int)(xc+r*Math.sqrt(3)*n),yc+r*n, xc,yc-2*r*n); //circumscribed circle has radius 2r g.drawOval(xc-2*r*n,yc-2*r*n, 4*r*n,4*r*n); //circumscribed circle } } }