Java 2D的加权数据插值插值、数据、Java

2023-09-11 03:04:27 作者:心若向阳无畏悲伤i

我试图找到一些的的Java LIB,code例子(或起点),以帮助我找出我怎么能插2D点的列表,包括权重生成一个插值水平曲线。

I'm trying to find some Java lib, code example (or a starting point) to help me figure out how can I interpolate a list of 2d points with a weight to generate a interpolation with level curves.

谷歌搜索我弄清楚,有可用一些算法要做到这一点,我发现了一些解释,提供有趣的内容。我想尝试的第一个算法是加权的反距离插。

Googling I figure out that there is several algorithms available to do this, and i found some explanations with interesting content. The first algorithm that I want to try is the Inverse Distance Weighted interpolation.

不过,所有这些信息,我有一些基本的疑惑:

But with all this information i have some basic doubts:

要生成一个图片像下面的图片,我必须做一个像素矩阵(体重),插值数据组像素在一起(颜色范围),再加入点就画出曲线,并把参考文本值如这?

如果的我必须这样做像素矩阵,这将是一个巨大的插值非常昂贵的,这样我就可以少做点,使用样条的加入,然后创建色阶?

If i need to do this pixel matrix, it will be very expensive for a giant interpolation, so can I do less points and use splines to join then to create the color levels?

示例数据:

+-------------------+
|  X  |  Y  | WEIGHT|
+-------------------+
|  2  |  5  |   30  |
|  7  |  3  |   25  |
|  1  |  1  |   10  |
|  5  |  6  |   45  |
|  7  |  9  |   15  |
+-------------------+

示例规则:

在00-10之间的值:蓝的 在10-20之间的值:绿色的 在20至30之间的值:黄的 在30-40之间的值:红色的 Value between 00-10: Blue Value between 10-20: Green Value between 20-30: Yellow Value between 30-40: Red

示例的结果:

的示例数据,规则和结果是不兼容的,只是随机的例子来解释我的prblem。的

下面是我最后的测试类: http://pastebin.com/nD6MT8eS

Here is my final test class: http://pastebin.com/nD6MT8eS

推荐答案

假设你有一个点类,你可以使用(例如java.awt.Point中),你可以把权重成图:

Assuming you've got a Point class you can use (e.g. java.awt.Point), you can put the weights into a Map:

Map<Point,Double> points = new HashMap<Point,Double>();
points.put( new Point(2,5), 30 )
...

然后,你做一个图像,并为每个x,y坐标,找到最好的成绩。我假定的得分是在表中的点的距离倒数倍的重量。如果是这样,是这样的:

Then, you make an image, and for each x,y coordinate, find the best score. I'm assuming that the score is the inverse distance times the weight of the point in the table. If so, it's like this:

image = createBitmap( width, height )
for( int x = 0; x < width; x++ )
    for( int y = 0; y < height; y++ )
    {
         double maxScore = -Double.MAX_VALUE
         for( Point p : points.keySet() ) 
         {
             double score = points.get(p)/p.distance( x, y ) //Inverse distance times point weight
             minDist = Math.max( maxScore, score )
         }
         image.setPixelColour( x, y, getColorForDistance( 1/minDist * points.get(p) )
    }

getColourForDistance(双DIST)应该是显而易见的,但你必须正确设置的级别。我假设createBitmap(宽,高)为创建图像。什么样的你正在做形象取决于你的应用程序一样,它是否有setPixelColour方法或类似。点类的选择将取决于您的应用程序也是如此。

getColourForDistance( double dist ) should be obvious, although you'll have to set the levels right. I'm assuming createBitmap( width, height ) is creates an image. What kind of image you're making depends on your application, as does whether it has a setPixelColour method or similar. Choice of points class will depend on your application as well.

此不进行优化 - 它至少为O(X * Y * P)其中p是点的数量。如果p变大,你可能想看看更合理的数据结构存储点。

This is not optimised - it's at least O(x*y*p) where p is the number of points. If p gets large, you might want to look at more sensible data structures for storing points.

 
精彩推荐