Coordinates within this class are with respect to the origin of the circle,
at (0,0). Thus, the square goes from (-S/2, -S/2) to (S/2, S/2).
Translation from my coordinates to Java's is handled by the private
drawLine, as explained below.
PI(int S, int n)
S. The approximation uses (approximately)
nline segments. No canvas is provided as a parameter so this class has to make its own. After the circle is drawn, a square of size SxS is drawn, so that the circle sits just inside the square.
numThrown() = numLandedIn() + numLandedOut()
From outside this class, we can compute an approximate to PI by
PI pi = new PI(100, 5); pi.hurlDarts(1000); double approx = 4.0 * pi.numLandedIn() / pi.numThrown();
void hurlDarts(int m)
m(additional) darts at the circle. You must do this part iteratively. Each dart is shown with a dot on the screen.
private void cirrecur(int oldX, int inc)
private int cirfunc(int x)
Ycoordinate for the supplied value of
private boolean insideCircle(int x, int y)
trueif the coordinates supplied are inside the circle; otherwise,
private void drawLine(myX1, myY1, myX2, myY2)(parameters are all
Startupto invoke your