Originally Posted by
jsuite
Urgent question: This is needed for the loop in ThrowDarts. So Throw darts basically checks if X and Y are inside the rectangle, then at the end of the loop it takes the number in range of x, and number in range of y, and then checks if it's inside the circle. How do I know if those numbers are in the coordinates of the circle? Basically need help / explanation of DartHits function.
Part c of loop instructions:
(4) Loop over N darts thrown, and count hits
a. Generate random # between [xmin,xmax]; call this xdart (xcoord of dart)
-> call xdart = RandNumInRange(xmin, xmax);
b. Generate random # between [ymin,ymax]; call this ydart (ycoord of dart)
-> call ydart = RandNumInRange(ymin, ymax);
c. hit = DartHits(xdart, ydart);
e. if hit != 0, add one to # of hits
Found the answer:
TESTER:
(1) Write function for shape we know answer to
--> circle has area PI*r*r
--> Easy to write function for circle wt center on axis!
--> Answer 1 if distance of (x,y) from axis <= r
--> distance: sqrt(x*x + y*y) (pythagorean theorem):
** draw grid wt triangle, to show how hypotenuse is the distance
--> RETURN 1 if sqrt(x*x + y*y) <= r, ELSE 0
==> Call this function:
int DartHits(double x, double y)
So due to the mixed references to "tester" I'm guessing "tester" is more than one function, instead a couple of functions that come before ThrowDarts()?