Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Wrong results for some points #1

Closed
sytolk opened this issue Jun 11, 2014 · 6 comments
Closed

Wrong results for some points #1

sytolk opened this issue Jun 11, 2014 · 6 comments
Labels

Comments

@sytolk
Copy link

sytolk commented Jun 11, 2014

/** insert this function in Tests.java and add it in main(..){ ..showBugTest(); 
     * test Polygon with Geo coordinates point: north:42.508956 east:27.483328
     */
    public static void showBugTest()
    {   //KML
        /*<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
  <Placemark>
        <name>Plygon</name>
        <LineString>
        <coordinates>
        27.485196,42.499148,1
                27.480000,42.498600,1
                27.474680,42.503800,1
                27.468270,42.510000,1
                27.466904,42.510788,1
                27.465350,42.512116,1
                27.467000,42.512000,1
                27.471027,42.513579,1
                27.472668,42.512938,1
                27.474922,42.511829,1
                27.480124,42.507945,1
                27.482892,42.509082,1
                27.490519,42.536026,1
                27.499703,42.534470,1
                27.485196,42.499148,1
                </coordinates>
                </LineString>
        </Placemark>
        </Document>
</kml>*/

        //you can view kml polygon here: http://display-kml.appspot.com/
        //and here is the point: https://maps.google.bg/?q=42.508956,27.483328

        Polygon polygon = Polygon.Builder()
                .addVertex(new Point(42.499148f, 27.485196f))
                .addVertex(new Point(42.498600f, 27.480000f))
                .addVertex(new Point(42.503800f, 27.474680f))
                .addVertex(new Point(42.510000f, 27.468270f))
                .addVertex(new Point(42.510788f, 27.466904f))
                .addVertex(new Point(42.512116f, 27.465350f))
                .addVertex(new Point(42.512000f, 27.467000f))
                .addVertex(new Point(42.513579f, 27.471027f))
                .addVertex(new Point(42.512938f, 27.472668f))
                .addVertex(new Point(42.511829f, 27.474922f))
                .addVertex(new Point(42.507945f, 27.480124f))
                .addVertex(new Point(42.509082f, 27.482892f))
                .addVertex(new Point(42.536026f, 27.490519f))
                .addVertex(new Point(42.534470f, 27.499703f))
                .addVertex(new Point(42.499148f, 27.485196f))
                .build();

        //I have view on the map that point (42.508956,27.483328) is inside the polygon. But the result of execution show that: The point:(42.51,27.48) is not inside the polygon
        isInside(polygon, new Point(42.508956f, 27.483328f)); //wrong results //function contains(..) -> intersection=0  why?
        isInside(polygon, new Point(42.505f,27.48f)); //but with an other point result is ok..
    }
@mccollumni
Copy link

I'm having the same issue. Using coordinates is not yielding the best results.

@VicV
Copy link

VicV commented Dec 2, 2015

@mccollumni convert all floats to doubles in these classes.

@ae-mo
Copy link

ae-mo commented Mar 20, 2016

That doesn't fix the problem

@fernandonm
Copy link

fernandonm commented Jul 8, 2016

Here a simple example of coordinates yielding a bad result:

        Polygon p = Polygon.Builder()
                .addVertex(new Point(40.481171f, 6.4107070f)) // NE
                .addVertex(new Point(40.480248f, 6.4101200f)) // SE. This point makes the test fail
                //.addVertex(new Point(40.480248f, 6.411029f)) // SE. But it works with this one
                .addVertex(new Point(40.480237f, 6.4062790f)) // SW
                .addVertex(new Point(40.481161f, 6.4062610f)) // NW
                .build();
        assertTrue(p.contains(new Point(40.480890f, 6.4081030f)));

@tatarize
Copy link

The code is flawed for any point hitting a vertex. If the ray drawn strikes a vertex exactly. Then that point counts as outside the polygon while it's inside the polygon.

@sromku sromku added the bug label Jul 2, 2017
@sromku sromku closed this as completed in 3173f2b Jul 2, 2017
@sromku
Copy link
Owner

sromku commented Jul 2, 2017

The main issue was with float. In my tests I didn't use coordinates and took such floating point precision into account. So obviously in this case double must be used. It's fixed.

I have tested and added tests for all failing examples in this issue.

You can use latest release 1.0.2 with the fixes - polygon-1.0.2.jar

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants