English 中文(简体)
Find Maximum Radius 圈 两条线路之间的每一处
原标题:Find Maximum Radius Circle Everywhere Between Two Lines

我有两波星,如下文所示。 有时,它们是相同的波浪,在轴心上刚刚转移。 其他时候,ine波有不同的时期/振荡等。

enter image description here

我需要找到符合以下两条内容的maximum radius圈(由我产生线的决议具体化)。

这样做的最佳方式是什么? 是否比在每一点与上 cur交之前,更快地形成一种对底曲线的圈子,并在半径上站起来?

问题回答

我不敢肯定,这是否是一个完整的答案,但它可能包含一些有益的想法。 (有些是数学,但我认为该守则也很重要,因此,我认为SO是这一问题的一个合理地点。)

enter image description here enter image description here

最后一个方程式可能有多种解决办法,但在实践中,>scipy.optimize.newton。 似乎趋向于最小的圆环。 而且,它具有矢量,因此你可以一劳永逸地解决几个方面的问题。

import numpy as np
from scipy.optimize import newton

import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
colors = list(mcolors.TABLEAU_COLORS.values())

# amplitude, angular frequency, phase, and y-offsets
params1 = 1, 1, 0, 0
params2 = 0.5, 0.5, 1, 2

# Sinusoid
def y(x, params):
    A, w, p, y = params
    return A*np.cos(w*x + p) + y

# Derivative of Sinusoid
def dy(x, params):
    A, w, p, y = params
    return -w*A*np.sin(w*x + p)

# Angle of Sinusoid Surface Normal
def phi(x, params):
    return np.arctan2(-1, dy(x, params))

# Radius of circle required given y-coordinates
def ry(y1, y2, phi1, phi2):
    return (y2 - y1)/(np.sin(phi1) + np.sin(phi2))

# Radius of circle required given x-coordinates
def rx(x1, x2, phi1, phi2):
    return (x2 - x1)/(np.cos(phi1) + np.cos(phi2))

# At the solution, the radius of the circle given y-coordinates
# must agree with the radius of the circle given x-coordinates
def f(x2, x1):
    y1, y2 = y(x1, params1), y(x2, params2)
    phi1, phi2 = phi(x1, params1), phi(x2, params2)
    return rx(x1, x2, phi1, phi2) - ry(y1, y2, phi1, phi2)

# Coordinate of center of circle
def x0y0(x1, r):
    y1 = y(x1, params1)
    phi1 = phi(x1, params1)
    return (x1 + r*np.cos(phi1), y1 + r*np.sin(phi1))

# Plot Sinusoids
t_plot = np.linspace(0, 15, 300)
y1 = y(t_plot, params1)
y2 = y(t_plot, params2)
plt.plot(t_plot, y1,  k , t_plot, y2,  k )
ax = plt.gca()
plt.ylim(-2, 4)
plt.axis( equal )

# Coordinates on sinusoid 1
x1 = np.asarray([1, 4.5, 7, 11, 13])
y1 = y(x1, params1)

# X-coordinates on sinusoid 2
x2 = newton(f, x1, args=(x1,))
y2 = y(x2, params2)

# Circle radii and centers
phi1 = phi(x1, params1)
phi2 = phi(x2, params2)
r = rx(x1, x2, phi1, phi2)
x0, y0 = x0y0(x1, r)

for i in range(len(x1)):
    color = colors[i]

    # Mark points on curve
    plt.plot(x1[i], y1[i], color, marker= * )
    plt.plot(x2[i], y2[i], color, marker= * )

    # Plot circles 
    circle = plt.Circle((x0[i], y0[i]), r[i], color=color, fill=False)
    ax.add_patch(circle)

“entergraph

Two caveats:

  • scipy.optimize.newton is not guaranteed to converge, and even if it does, it is not guaranteed to converge to the circle with minimum radius (unless it can be proven otherwise...). If it is not reliable for your particular parameters but you like the approach, consider posting a more specific question about how to reliably solve the relevant equations numerically. It may just be a matter of solving for one circle and using that as the guess for the next circle.
  • This code doesn t consider the possibility of the circle intersecting with a second point on the lower curve before it touches the upper curve. I couldn t tell from the problem statement if this was required because the question mentioned "stepping up in radius until intersection with the upper curve". This is easy enough to check, though, due to symmetry of the convex portion of the sinusoid.




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签