Processing math: 100%

Coding challenge

Write some code to estimate the probability that 3 random points on the edges of a square form an obtuse triangle. The law of cosines may help, which is cosθ=(b2+c2a2)/2bc. Hint: sketch this first. Draw a square and put the random points P1, P2, and P3 on 3 of its sides. Connect the three points with lines and see the resulting triangle. Apply the law of cosines as needed. (From Cheney, p. 588.)

Type your code here:

 
1

Lua reference

See your results here: