Update fourth.py
This commit is contained in:
@@ -1,15 +1,30 @@
|
|||||||
import random
|
import random
|
||||||
from numpy import pi, cos, sin, sqrt
|
from numpy import pi, cos, sin, sqrt
|
||||||
|
|
||||||
|
|
||||||
|
def distance(pointa, pointb):
|
||||||
|
return sqrt((pointa[0] - pointb[0]) ** 2 + (pointa[1] - pointb[1]) ** 2)
|
||||||
|
|
||||||
|
|
||||||
|
def create_point():
|
||||||
|
angle = random.uniform(0, 2*pi)
|
||||||
|
x = cos(angle)
|
||||||
|
y = sin(angle)
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
|
def check_acute(a, b, c):
|
||||||
|
if a**2 + b**2 > c ** 2:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
for _ in range(100000):
|
for _ in range(100000):
|
||||||
(x1, y1) = (cos(random.uniform(0, 2*pi)), sin(random.uniform(0, 2*pi)))
|
x1, x2, x3 = create_point(), create_point(), create_point()
|
||||||
(x2, y2) = (cos(random.uniform(0, 2 * pi)), sin(random.uniform(0, 2 * pi)))
|
l = [distance(x1, x2), distance(x1, x3), distance(x2, x3)]
|
||||||
(x3, y3) = (cos(random.uniform(0, 2 * pi)), sin(random.uniform(0, 2 * pi)))
|
l.sort()
|
||||||
len1 = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
if check_acute(l[0], l[1], l[2]):
|
||||||
len2 = sqrt((x3 - x1) ** 2 + (y3 - y1) ** 2)
|
|
||||||
len3 = sqrt((x3 - x2) ** 2 + (y3 - y2) ** 2)
|
|
||||||
if len1 ** 2 + len2 ** 2 > len3 ** 2 and len2 ** 2 + len3 ** 2 > len1 ** 2 and len1 ** 2 + len3 ** 2 > len2 ** 2:
|
|
||||||
counter+=1
|
counter+=1
|
||||||
print(counter/100000)
|
print(counter/100000)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user