gpt4 book ai didi

python - 从曲线形状中获取均匀分布的点

转载 作者:行者123 更新时间:2023-12-01 22:46:09 25 4
gpt4 key购买 nike

我如何获取在其曲线上有更多点创建的形状并将其分割,以便这些点沿曲线更均匀地分布?在我的研究中,我认为 numpyinterp可能是正确的功能,但我不知道参数使用什么 (x, xp, fp, left, right, & period).任何帮助将不胜感激!

这是一个显示所需输出的动画。

Example of Shape with Even Distribution

这是输入圆角矩形的代码:

from matplotlib import pyplot as plt
import numpy as np

x_values = [1321.4, 598.6, 580.6, 563.8, 548.6, 535.4, 524.5, 516.2, 511,
509.2, 509.2, 511, 516.2, 524.5, 535.4, 548.6, 563.8, 580.6, 598.6, 1321.4, 1339.4,
1356.2, 1371.4, 1384.6, 1395.5, 1403.8, 1409, 1410.8, 1410.8, 1409, 1403.8, 1395.5,
1384.6, 1371.4, 1356.2, 1339.4, 1321.4]
y_values = [805.4, 805.4, 803.5, 798.3, 790.1,
779.2, 766, 750.8, 734, 716, 364, 346, 329.2, 314, 300.8, 289.9, 281.7, 276.5, 274.6,
274.6, 276.5, 281.7, 289.9, 300.8, 314, 329.2, 346, 364, 716, 734, 750.8, 766, 779.2,
790.1, 798.3, 803.5, 805.4]

fig, ax = plt.subplots(1)
ax.plot(x_values,y_values)
ax.scatter(x_values,y_values)
ax.set_aspect('equal')
plt.show()

谢谢!

最佳答案

enter image description here

from matplotlib import pyplot as plt
import numpy as np

x = np.array([1321.4, 598.6, 580.6, 563.8, 548.6, 535.4, 524.5, 516.2, 511,
509.2, 509.2, 511, 516.2, 524.5, 535.4, 548.6, 563.8, 580.6, 598.6, 1321.4, 1339.4,
1356.2, 1371.4, 1384.6, 1395.5, 1403.8, 1409, 1410.8, 1410.8, 1409, 1403.8, 1395.5,
1384.6, 1371.4, 1356.2, 1339.4, 1321.4])
y = np.array([805.4, 805.4, 803.5, 798.3, 790.1,
779.2, 766, 750.8, 734, 716, 364, 346, 329.2, 314, 300.8, 289.9, 281.7, 276.5, 274.6,
274.6, 276.5, 281.7, 289.9, 300.8, 314, 329.2, 346, 364, 716, 734, 750.8, 766, 779.2,
790.1, 798.3, 803.5, 805.4])

fig, ax = plt.subplots(1)
ax.set_aspect('equal')
ax.scatter(x, y, s=40, zorder=3, alpha=0.3)

# compute the distances, ds, between points
dx, dy = x[+1:]-x[:-1], y[+1:]-y[:-1]
ds = np.array((0, *np.sqrt(dx*dx+dy*dy)))

# compute the total distance from the 1st point, measured on the curve
s = np.cumsum(ds)

# interpolate using 200 point
xinter = np.interp(np.linspace(0,s[-1], 200), s, x)
yinter = np.interp(np.linspace(0,s[-1], 200), s, y)

# plot the interpolated points
ax.scatter(xinter, yinter, s=5, zorder=4)
plt.show()

关于python - 从曲线形状中获取均匀分布的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75416188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com