快速插值或在点阵列中找到点? [英] Interpolate or find a point in a point array fast?

查看:64
本文介绍了快速插值或在点阵列中找到点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我还是vb.net的新手,遇到了另一个应该很容易解决的问题,但是经过很长时间,我仍然无法锻炼正确的方法.

我有一个很大的一维点数组,这些点具有唯一的Y和不同的X,并且我想在提供Y时线性地对X进行插值.

我通过遍历数组的迭代计数器找到最近的点来使其工作.不幸的是它太慢了.我确实看到.NET具有带有谓词的array.find,但是我看不到将已知Y传递给谓词的明智方法吗?

感谢收到任何建议!

谢谢.

解决方案

如果使用List(Of Point)而不是数组,则可以使用

 Points.Where(功能(p)pY =  34 ). .X 



另外,如果您的Y不唯一地出现在数组中,请查找如何计算直线方程(y = mx + c)并将其用于数组中的几个点,然后可以使用它来计算X表示Y的任何值

由于对数组进行了排序,因此您可以实现二进制搜索 [ ^ ].


Hi,

I''m still new to vb.net and have come up against another problem that should be easy to solve but after much time I still can''t workout how to do it right.

I have a large 1d array of points which have unique Y''s and varying X''s and I want to linearly interpolate an X when provided with a Y.

I have got it working by finding the nearest point via an iterating counter through the array. Unfortunately it is too slow. I did see that .NET has the array.find with predicate but I couldn''t see a sensible way of passing the known Y to the predicate?

Any suggestions gratefully received !

Thanks.

解决方案

If you use a List(Of Point) instead of an array, you can use

Points.Where(Function(p) p.Y = 34).First.X



Alternatively, if your Y is not excepted to be in the array, look up how to calculate the equation of a line ( y = mx + c ) and use this against a couple of points from your array, then you can use this to calculate an X for any value of Y


Since your array is sorted you may implement a binary search[^].


这篇关于快速插值或在点阵列中找到点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆