如何对由多项式参数化的二维空间中的曲线进行积分?

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

我在 2D 空间中有一条简单的曲线

(x, y)
,它由多项式参数化为
t
的函数,我想知道该曲线的长度。我该如何做到这一点?我研究了
scipy.integrate
numpy.polyint
但我没有找到解决方案。似乎它们都只能在一维多项式上积分。这是曲线的示例:

import numpy as np
from scipy import integrate


x0, y0 = 0.0, 0.0
vx, vy = 0.1, 0.1
ax, ay = -0.0001, 0
coeff = np.array([[ax, ay], [vx, vy], [x0, y0]])

pos = lambda t: np.polyval(coeff, t)
python numpy scipy numerical-integration polynomials
1个回答
2
投票

弧长是曲线参数的单变量多项式。您需要定义弧长微分的表达式,然后就可以对其进行积分,如注释中的链接中所述。正如您所看到的,它可以简单地表示为向量

(dx/dt, dy/dt)
的欧几里德范数。因此,您可以按照以下方式实施它:

import numpy as np
import scipy

x0, y0 = 0.0, 0.0
vx, vy = 0.1, 0.1
ax, ay = -0.0001, 0
coeff = np.array([[ax, ay], [vx, vy], [x0, y0]])

# Position expression is not really necessary
pos = lambda t: np.polyval(coeff, t)

# Derivative of the arc length
def ds(t):
    # Coefficients of polynomial derivative
    coeff_d = coeff[:-1] * np.arange(len(coeff) - 1, 0, -1)[:, np.newaxis]
    # Norm of position derivatives
    return np.linalg.norm(np.polyval(coeff_d, np.expand_dims(t, -1)), axis=-1)

# Integrate across parameter interval
t_start, t_end = 0, 1
arc_length, err = scipy.integrate.quad(ds, t_start, t_end)
print(arc_length)
# 0.1413506691471052

当然,你可以尝试求出

ds
积分的解析表达式,然后就不需要任何积分方法了。

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