Three points are chosen at random inside a square. Each point is chosen by choosing a random x-coordinate and a random y-coordinate.
A triangle is drawn with the three random points as the vertices. What is the probability that the center of the square is inside the triangle?
(In reply to
re(3): Not faster, simpler, or better by ed bottemiller)
As an example of a point other than the center to be tested for inclusion in the triangle, take a point that's midway between the center and one of the corners of the square, at (0.75,0.75) (for a square with diagonal from (0,0) to (1,1).
In 1,000,000 trials, 92,807 of the time this point was within the triangle, for a probability of 0.092807. To allow for the vagaries of the simulation, say 0.0928 or 0.093. That's quite a bit smaller than 1/4. It's between 1/10 and 1/11.
DEFDBL A-Z
FOR i = 1 TO 1000000
x1 = RND(1): y1 = RND(1)
x2 = RND(1): y2 = RND(1)
x3 = RND(1): y3 = RND(1)
m = (y2 - y1) / (x2 - x1)
a = y1 - m * x1
test1 = y3 - (m * x3 + a)
test2 = .75 - (m * .75 + a)
m = (y3 - y1) / (x3 - x1)
a = y1 - m * x1
test3 = y2 - (m * x2 + a)
test4 = .75 - (m * .75 + a)
m = (y3 - y2) / (x3 - x2)
a = y2 - m * x2
test5 = y1 - (m * x1 + a)
test6 = .75 - (m * .75 + a)
IF test1 * test2 > 0 AND test3 * test4 > 0 AND test5 * test6 > 0 THEN
hit = hit + 1
END IF
ct = ct + 1
PRINT hit, ct, hit / ct
NEXT
|
Posted by Charlie
on 2008-03-18 16:49:16 |