我如何找到两个未排序的x,y阵列中的区域?

发布于 2025-02-04 03:02:57 字数 721 浏览 1 评论 0原文

我想发现在区域内部受到两个未排序阵列(x和y)的限制。 如果他们进行了排序,我只能按照此

theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)
x = np.sin(theta)
y = np.cos(theta)
answer = np.trapz(y, x=x)

其中X和Y数组的正确排序以允许Trapz正确功能的方式(即使端点= false)。 但是,在我的数据中,X和Y没有分类。我想找到由X和Y包围的区域,如以下示例中所述:

theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)

ii = np.arange(len(x))
np.random.shuffle(ii)

x = np.sin(theta)[ii]
y = np.cos(theta)[ii]
answer = np.trapz(y, x=x) #This no longer gives the correct integral.

是否有一种方法可以找到阵列所包围的区域而不按角度进行排序?它不必使用trampz。谢谢

I want to find the are inside the region limited by two unsorted arrays (x and y).
If they were sorted, I could just follow this example:

theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)
x = np.sin(theta)
y = np.cos(theta)
answer = np.trapz(y, x=x)

In which the x and y array are correctly sorted in a way that allows trapz to correctly function (even if endpoint=False).
However, in my data x and y are not sorted. I would like to find the area enclosed by x and y as given in the following example:

theta = np.linspace(0, 2 * np.pi, num=1000, endpoint=True)

ii = np.arange(len(x))
np.random.shuffle(ii)

x = np.sin(theta)[ii]
y = np.cos(theta)[ii]
answer = np.trapz(y, x=x) #This no longer gives the correct integral.

Is there a way to find the area enclosed by the arrays without sorting by angular position? It doesn't have to be using trampz. Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2025-02-11 03:02:57

我尚未尝试但最终简单地通过角位置对点进行排序,并在(假设点实际包围了一个表面)只是使用陷阱集成。我在此答案中包括我使用的方法。

def integrate_contours(x,y):
    xx = x - x.mean()
    yy = y - y.mean()
    theta_2 = np.arctan2(xx,yy)
    yy = yy[np.argsort(theta_2)]
    xx = xx[np.argsort(theta_2)]
    
    return np.abs(np.trapz(yy, x=xx))

I have yet to try Convex Hull, but ended up simply sorting the points by angular position and (under the assumption that points actually enclose a surface) just integrated using trapz. I include in this answer the method I used.

def integrate_contours(x,y):
    xx = x - x.mean()
    yy = y - y.mean()
    theta_2 = np.arctan2(xx,yy)
    yy = yy[np.argsort(theta_2)]
    xx = xx[np.argsort(theta_2)]
    
    return np.abs(np.trapz(yy, x=xx))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文