This commit is contained in:
Michael Zhang 2020-12-07 19:41:32 -06:00
parent 0fe7e86519
commit b08be585bc
Signed by: michael
GPG Key ID: BDA47A31A3C8EE6B
1 changed files with 11 additions and 10 deletions

21
727.py
View File

@ -1,6 +1,7 @@
import sympy
import joblib
import tqdm
import multiprocessing
def gcd(a, b):
if b == 0: return a
@ -44,7 +45,6 @@ def inv_law_cosines(a, b, c):
# given a, b, c return C
return sympy.acos((a * a + b * b - c * c) / (sympy.S(2) * a * b))
def compute_d(A: Point, B: Point, C: Point, r1: float, r2: float, r3: float) -> float:
r1, r2, r3 = sympy.S(r1), sympy.S(r2), sympy.S(r3)
@ -53,14 +53,15 @@ def compute_d(A: Point, B: Point, C: Point, r1: float, r2: float, r3: float) ->
CAmid = lerp(C, A, r3)
D = circumcenter(ABmid, BCmid, CAmid)
re = sympy.symbols("re")
t1 = heron(r1 + r3, r1 + re, r3 + re)
t2 = heron(r1 + r2, r1 + re, r2 + re)
t3 = heron(r2 + r3, r2 + re, r3 + re)
tfull = heron(r1 + r2, r1 + r3, r2 + r3)
eq = sympy.Eq(t1 + t2 + t3, tfull)
result = sympy.solve(eq, re)
result = result[0].evalf()
result = r1 + r2 + r3 + sympy.S(2) * sympy.sqrt(r1 * r2 + r2 * r3 + r1 * r3)
# re = sympy.symbols("re")
# t1 = heron(r1 + r3, r1 + re, r3 + re)
# t2 = heron(r1 + r2, r1 + re, r2 + re)
# t3 = heron(r2 + r3, r2 + re, r3 + re)
# tfull = heron(r1 + r2, r1 + r3, r2 + r3)
# eq = sympy.Eq(t1 + t2 + t3, tfull)
# result = sympy.solve(eq, re)
# result = result[0].evalf()
# print(f"radius of E is {result}")
EAB = inv_law_cosines(r1 + result, r1 + r2, r2 + result)
@ -104,5 +105,5 @@ def calc(x):
print(f"d({r1}, {r2}, {r3}) = {d}")
total = len(list(create_loop()))
L = joblib.Parallel(n_jobs=8)(joblib.delayed(calc)(tup) for tup in tqdm.tqdm(create_loop(), total=total))
L = joblib.Parallel(n_jobs=multiprocessing.cpu_count())(joblib.delayed(calc)(tup) for tup in tqdm.tqdm(create_loop(), total=total))
print(sum(L) / len(L))