A friend of mine went on an interview and he was asked to calculate the angle between the hour hand and minute hand of an analog clock when the time was 3:15.
Arguably, this is a trivial problem that can be easily solved analytically. 15 minutes is the 1/4th of an hour, and an hour is the 1/12th of a full circle, therefore the angle is $(1/4)\times(1/12)\times 360 = 7.5 \deg$. I was wondering whether a Monte Carlo simulation could do well.
EDITED: As suggested by @kuba here is the image of a "real" clock hopefully at 3:15 precisely.
Source: http://etc.usf.edu/clipart/33000/33069/clock-03-15_33069.htm
My code that follows operates on the mask of an ideal clock at 3:15 (angle between two hands at 7.5
degrees) and not on a mask generated by the above image. It takes more than $10^6$ points to derive an answer of $\sim 7 \deg$. Could the experts here improve the accuracy of the simulation?
ClearAll["Global`*"];
(* Generate some random points. Use 0.98 instead of 1.00 or otherwise
some points will be half-inside the circle and half-outside.
This will hurt our results in left untreated. *)
points = Show[
Graphics[{Pink,
Point /@
Select[
Partition[RandomReal[{-1, 1}, 10000], 2],
({a, b} = #; a^2 + b^2 <= 0.98) &]}]]
(* In reality the mask below should have been generated by a real clock *)
disk = Graphics[{Pink, Disk[{0, 0}, 1, {0, 2π - 7.5π/180}]}]
finalImage = ImageSubtract[disk, Show[disk, points]]
(* Count the number of points inside the slice and outside the slice.
If I use "Count" as the property in ComponentMeasurements[], I get worse results.
EDITED: As noted by @MichaelE2 the following statement for 'outArea'
might calculate the whole rectangular area and not only the points! *)
inArea = Last /@ ComponentMeasurements[finalImage, "Area"] // Total;
outArea = Last /@ ComponentMeasurements[points, "Area"] // Total;
(inArea/outArea) * 360 // N
EDITED: With the point set by @DanielLichtblau, I get $\sim 7.3$ degrees with $10^4$ points! finalImage
looks like this:
pts = Point[ Select[Flatten[ Table[2*Mod[{j*GoldenRatio, k*GoldenRatio}, 1.] - 1, {j, 2*100}, {k, 2*100}], 1], #[[1]]^2 + #[[2]]^2 < .99 &]];
$\endgroup$