dem-net / DEM.Net

Digital Elevation model library in C#. 3D terrain models, line/point Elevations, intervisibility reports
https://elevationapi.com
Other
306 stars 56 forks source link

Wrong y direction in HyperbolicInterpolator #98

Open g0ro opened 3 years ago

g0ro commented 3 years ago

https://github.com/dem-net/DEM.Net/blob/168cd8e0e277793227f9cacd1cd26310ba495928/DEM.Net.Core/Services/Interpolation/HyperbolicInterpolator.cs#L44

If x is from west to east and y is from north to south, then (0,0) point should be at NW, not SW

xfischer commented 3 years ago

Hi @g0ro, thanks for reporting this. Can you submit a test case for that ? Which data set did you use ?

g0ro commented 3 years ago

It does not depend on a dataset. HyperbolicInterpolator's y is just inversed compared to BilinearInterpolator. The later seems to be right.

To test it, we may get height values of corner points, they should be the same:


        private static void TestInterpolators()
        {
            var iplBl = new BilinearInterpolator();
            var iplHb = new HyperbolicInterpolator();

            for (var x = 0; x<=1; x++)
            {
                for (var y = 0; y <= 1; y++)
                {
                    var hBl = iplBl.Interpolate(1, 2, 3, 4, x, y);
                    var hHb = iplHb.Interpolate(1, 2, 3, 4, x, y);
                    Console.WriteLine($"x={x} y={y} hBl={hBl} hHb={hHb}");
                }

            }

        }

But the result is inverted:

x=0 y=0 hBl=3 hHb=1
x=0 y=1 hBl=1 hHb=3
x=1 y=0 hBl=4 hHb=2
x=1 y=1 hBl=2 hHb=4
xfischer commented 3 years ago

OK thanks for pointing this out. Will fix it