Point in Polygon algorithm giving wrong results for negative points

后端 未结 1 1282
深忆病人
深忆病人 2021-01-29 12:50

I am trying to check if the lat,lon is in the polygon or not. Here is my array :

$vertices_x : 
Array
(
    [0] => -32.581189
    [1] => -38.785885
    [2         


        
相关标签:
1条回答
  • 2021-01-29 13:15

    I don't think your point (173.5385,-34.472) is in the polygon.

    Your x value is much larger than the largest x vertex. You can see this if you plot it. You can see from the orange point that even if you just have your lat/long mixed up it's still not in the polygon.

    EDIT:

    Upon first inspection of your new polygon and point it looks as though this one is more likely to be contained within the polygon (x_min < x < x_max and y_min < y < y_max).

    -36.236432, 176.467563
    -37.936530, 172.688266
    -39.801068, 177.895786
    -35.345287,-177.446011
    -34.625208,-177.907437 
    

    point:

    (-37.0278,176.6158)
    

    However, plotting this again reveals that the point is outside the polygon:

    ... and zooming in ...


    I plotted these in python with matplotlib and I recommend you do something similar when debugging this type of thing. If you want to stay with php, html, etc., you could use svg polygons or html canvas instead.

    0 讨论(0)
提交回复
热议问题