How do I find the radius of the largest circle which fits the following curve, y=sin(x)
?
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0,1.01*np.pi,0.01) # start,stop,step
y = np.sin(x)
plt.plot(x,y)
plt.show()
CodePudding user response:
You can solve this problem analytically using a basic maths (parametric) equation system. Indeed, the circle can be described by the algebraic expression x² y² ≤ r²
. The one of the shape below your curve is 0 ≤ y ≤ sin(x)
. The definition domain of x
is [0,π[
(you can find it analytically or numerically using the
The best solution is r=0.5
.
Assuming the curve have a complex definition (possibly not an analytic one), you can solve this problem using optimization methods. For example, you can use scipy.optimize
.