Проверка на нахождение точки в полигоне

function isPointInPolygon($poly, $point){

    $c = false; 
    $n = $j = count($poly);


    for ($i = 0, $j = $n - 1; $i < $n; $j = $i++){

        if ( ( ( ( $poly[$i][0] <= $point[0] ) && ( $point[0] < $poly[$j][0] ) ) 
              || ( ( $poly[$j][0] <= $point[0] ) && ( $point[0] < $poly[$i][0] ) ) ) 

            && ( $point[1] <   ( $poly[$j][1] - $poly[$i][1] ) 
                * ( $point[0]    - $poly[$i][0] ) 
                / ( $poly[$j][0] - $poly[$i][0] ) 
                +   $poly[$i][1] ) ){

            $c = !$c;
        }
    }

    return $c;
}

На главную