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] => -39.26384
[3] => -34.919383
[4] => -32.284464
)
$vertices_y:
Array
(
[0] => 170.643905
[1] => 170.424179
[2] => -178.15004
[3] => -176.524063
[4] => -178.325821
)
$longitude_x : 173.5385
$latitude_y : -34.472
$points_polygon = count($vertices_x) - 1;
I am using below function to check :
function is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y) {
$i = $j = $c = 0;
for ($i = 0, $j = $points_polygon; $i < $points_polygon; $j = $i++) {
if ((($vertices_y[$i] > $latitude_y != ($vertices_y[$j] > $latitude_y)) &&
($longitude_x < ($vertices_x[$j] - $vertices_x[$i]) * ($latitude_y - $vertices_y[$i]) / ($vertices_y[$j] - $vertices_y[$i]) + $vertices_x[$i])))
$c = !$c;
}
return $c;
}
And this function always gives me 0 (Not in polygon) but if you check then my point $longitude_x : 173.5385 , $latitude_y : -34.472
is in that polygon area.
I think the above algorithm in the function is only work with positive values.