用Python计算椭圆的直肠阔部

2024-09-27 07:24:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图计算通过椭圆焦点的半横断直肠(L)的长度(例如,图中的蓝线取自http://mathworld.wolfram.com/SemilatusRectum.html

Semilatus Rectum

在哪里

L=a(1-e**2)(http://mathworld.wolfram.com/SemilatusRectum.html

以及

e=c/a(http://mathworld.wolfram.com/Eccentricity.html

我用python编写了这段代码来计算L,但是没有得到预期的结果。在

我的代码是:

import math
import matplotlib.pyplot as plt

a = 10 # semimajor axis
b = 5 # semiminor axis

# calculate and plot semilatus rectum
for c in range(0, a):
    eccentricity = c / a
    L = (a-c) * (1. - eccentricity**2)
    plt.plot([0, L], [c, c])

# plot ellipse
for t in range(0, 360):
    x = a*math.cos(t)
    y = b*math.sin(t)
    plt.scatter(b*math.cos(t), a*math.sin(t), s=1, c="r", edgecolor="none")

结果是:

Semilatus Rectum result

#######更新

多亏了@slatertyranus,我才意识到我问题中的错误


Tags: 代码inimportcomhttpforplothtml
1条回答
网友
1楼 · 发布于 2024-09-27 07:24:13

你的问题让我有点困惑,但下面是如何计算椭圆的直肠大部:

import math

def latum_rectum(semi_minor, semi_major):
    focus_distance = math.sqrt(semi_major**2 - semi_minor**2)
    eccentricity = focus_distance/semi_major
    return 2*semi_major(1 - eccentricity**2)

我希望这有帮助。我还不知道你想怎么处理这个情节,所以如果你还有什么问题,请告诉我。在

相关问题 更多 >

    热门问题