如何找到隐式曲线的交点

问题描述 投票:0回答:1

我制作的以下程序用于绘制隐式开普勒方程:

y - e sin(y) = x
(其中平均异常
x
运行到
180°

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from numpy import sin, radians

y_range = np.linspace(0, 180)
x_range = np.linspace(0, 180)
y, x = np.meshgrid(y_range, x_range)

color = "red"
e = 0.90

fig, ax = plt.subplots(1, 1, figsize = (6, 3), tight_layout = True)
 
f = lambda y, x, e: radians(y) - e*sin(radians(y)) - radians(x)
equation = f(y, x, e)

ax.contour(x, y, equation, levels = [0], colors = color)

ax.set_xticks([i for i in range(0, 180+1, 15)])
ax.set_yticks([i for i in range(0, 180+1, 15)])
ax.set_xlabel("x : Mean Anomaly (deg)")
ax.set_ylabel("y : Eccentric Anomaly (deg)")

# line at point x = 15°
ax.axvline(x = 15)   

plt.show()

通过运行程序可以看到,

x=15°
处设置的垂直线在大约
60
°处切割隐式曲线...

我想知道,在这种情况下,是否存在一种简单的Python方式来获取交点的坐标......

我发现一般可以使用

%pip install intersect
,然后使用
from intersect import intersection
,但我根本不明白如何在我的程序中应用它?

有人有办法解决这个问题吗?或者你认为这需要对程序进行彻底的重新制定吗?

python-3.x intersection curve
1个回答
0
投票

既然你可以使用

intersect
包(例如,你不是在寻找这个的自定义实现),我想你所缺少的是如何获取由
ax.contour
创建的轮廓线?

cont = ax.contour(...)
lines = cont.allsegs # a list of arrays containing the coordinates of the contour lines

然后您需要做的就是选择您想要的轮廓线并评估交点。

© www.soinside.com 2019 - 2024. All rights reserved.