As an extension problem which my math teacher gave me, I was asked to solve for the maximum area of triangle, with each of its vertices on a circle of radius 3,4,5 respectively. I got the answer alright (20.495) but the solution is very awkward and the calculus approach I used is definitely not the most convenient one (the solution is sketched in this Desmos file: https://www.desmos.com/calculator/fydjs4wfbm). I am not that interested in this specific problem now and my Current question is how can one solve the problem when it's generalized to an N-sided polygon, with each of its vertex on a different circle, having N concentric circles in total whose radii can be any number as long as they have different values.
I have some code here that uses the method provided by Empy2 (thetaj=arccos(min(1,k/(rjrj+1))) )) (if you have your own idea then ignore it). It looks like a good estimate so I added the code here. But problem still exists when n<6, because k has to be negative for these ns and arccos(x) is undefined when x<-1, so there will be math error when the program does arccos(min(1,k/r1r2)), when k/r1r2 <-1.
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
ax.axis('equal')
theta = np.linspace(0, 2 * np.pi, 1500)
# number of circles
#works for n>5
n = 3
radius = [i for i in range(1, n+1)]
def asum(k):
Sum = 0
for i in range(1, n):
if i == n - 1:
a = np.arccos(min(1, k/(radius[i]*(radius[i]+1))))
if a != 0:
Sum += a
else:
a = np.arccos(min(1, k/(radius[i]*radius[i+1])))
if a != 0:
Sum += a
return Sum
#works for n>5
def findbest(s, e, n):
real = 2*np.pi
for i in range(50):
mid = (s+e)/2
midV = asum(mid)
if midV < real:
e = mid
if midV > real:
s = mid
return (s+e)/2
#k=findbest(startvalue,endvalue,n) add sensible start and END value -70
s = 0
e = 100000000
k = findbest(s,e, n)
print("aprox k:", k)
angles = [0]
A = []
# update angles
for i in range(1, n):
if i == n - 1:
a = np.arccos(min(1, k/(radius[i]*(radius[i]+1))))
angles.append(a+angles[len(angles)-1])
if a != 0:
A.append(a)
else:
a = np.arccos(min(1, k/(radius[i]*radius[i+1])))
angles.append(a+angles[len(angles)-1])
if a != 0:
A.append(a)
X = []
Y = []
for i in range(len(angles)):
X.append(radius[i] * np.cos(angles[i]))
Y.append(radius[i] * np.sin(angles[i]))
area = 0.5*abs((X[len(X)-1]*Y[0] - Y[len(Y)-1] * X[0]))
for i in range(0, len(X)-1):
area += 0.5*(X[i] * Y[i+1] - X[i+1] * Y[i])
print("Area:", area)
#####
# plot circle
xs = []
ys = []
for i in range(0, len(radius)):
xs.append(radius[i] * np.cos(theta))
ys.append(radius[i] * np.sin(theta))
for i in range(len(xs)):
ax.plot(xs[i], ys[i], linewidth=0.4, c='black')
######
plt.plot(X, Y, linewidth=1.75, color='b')
plt.plot([radius[0], radius[len(radius)-1]*np.cos(sum(A))],
[0, radius[len(radius)-1]*np.sin(sum(A))], color='b', linewidth=1.75)
print("Sum of angles:", "R:", sum(A), "D:", sum(A)*180/np.pi)
print(" 2pi - sum of angles:", "R:", sum(A)-2 *
np.pi, "D:", 180/np.pi * (sum(A)-2*np.pi))
plt.show()