2) and isset($pointAr[0]) and isset($pointAr[1])) { $rayAr = array_shift($pointsAr); if (isset($rayAr[0]) and isset($rayAr[1])) { $rayK = true; $rayB = 0; $rayDirectionX = true; $rayDirectionY = true; if ($rayAr[0] == $pointAr[0]) { if ($rayAr[1] == $pointAr[1]) {return true;} if ($rayAr[1] > $pointAr[1]) {$rayDirectionY = false;} } elseif ($rayAr[1] == $pointAr[1]) {echo 7; $rayK = 0; $rayB = $rayAr[1]; if ($rayAr[0] > $pointAr[0]) {$rayDirectionX = false;} } else { $rayK = ($pointAr[1] - $rayAr[1]) / ($pointAr[0] - $rayAr[0]); $rayB = $rayAr[1] - ($rayAr[0] * $rayK); if ($rayAr[0] > $pointAr[0]) {$rayDirectionX = false;} if ($rayAr[1] > $pointAr[1]) {$rayDirectionY = false;echo "888";} } $pointsAr = array_merge($pointsAr,array($rayAr)); //var_dump($pointsAr);exit; $pointLastX = $rayAr[0]; $pointLastY = $rayAr[1]; $count = 0; echo "Ray direction x: ";if ($rayDirectionX) {echo "true";} else {echo "false";}echo "\n"; echo "Ray direction y: ";if ($rayDirectionY) {echo "true";} else {echo "false";}echo "\n"; echo "Ray k: ";if ($rayK === true) {echo "true";} elseif ($rayK === false) {echo "false";} else {echo $rayK;}echo "\n"; echo "Ray b: $rayB\n"; echo "Ray coordinates [${rayAr[0]},${rayAr[1]}] - [${pointAr[0]},$pointAr[1]]\n"; foreach ($pointsAr as $keyyy => $pointItemAr) { echo "Новая точка полигона $keyyy.\n"; if (!isset($pointItemAr[0]) or !isset($pointItemAr[1])) {echo "Тест:$keyyy\n";var_dump($pointItemAr);return false;} if (!(($pointLastX == $pointItemAr[0]) and ($pointLastY == $pointItemAr[1]))) {//точка не совпадает с предыдущей if ((($rayDirectionX and (($pointItemAr[0] >= $pointAr[0]) or ($pointLastX >= $pointAr[0]))) or (!$rayDirectionX and (($pointItemAr[0] < $pointAr[0]) or ($pointLastX < $pointAr[0])))) and ($rayDirectionY and ((($pointItemAr[1] >= $pointAr[1]) or ($pointLastY >= $pointAr[1]))) or (!$rayDirectionY and (($pointItemAr[1] < $pointAr[1]) or ($pointLastY < $pointAt[1]))))) { if (($pointItemAr[0] == $pointAr[0]) and ($pointItemAr[1] == $pointAr[1])) {return true;}//если точка полигона совпадает с точкой для которой определяется вхождение $lineK = true; $lineB = true; $lineDirectionX = true; $lineDirectionY = true; if ($pointLastX == $pointItemAr[0]) { if ($pointLastY == $pointItemAr[1]) {return true;} if ($pointLastY > $pointItemAr[1]) {$lineDirectionY = false;} } elseif ($pointLastY == $pointItemAr[1]) { $lineK = 0; $lineB = $pointItemAr[1]; if ($pointLastX > $pointItemAr[0]) {$lineDirectionX = false;} } else { echo "иначе\n"; echo "линия [$pointLastX,$pointLastY] - [${pointItemAr[0]},${pointItemAr[1]}]\n"; $lineK = ($pointItemAr[1] - $pointLastY) / ($pointItemAr[0] - $pointLastX); echo "($pointItemAr[1] - $pointLastY) / ($pointItemAr[0] - $pointLastX)\n"; $lineB = $pointLastY - ($lineK * $pointLastX); if ($pointLastX > $pointItemAr[0]) {$lineDirectionY = false;} if ($pointLastY > $pointItemAr[1]) {$lineDirectionX = false;} if ($rayK === true) { $pointInterSectionY = $lineK * $itemPointAr[0] + $lineB; if (($pointLastY < $pointInterSectionY) and ($pointItemAr[1] >= $pointInterSectionY)) {$count++;} elseif (($pointLastY >= $pointInterSectionY) and ($pointItemAr[1] < $pointInterSectionY)) {$count--;} } else { $pointInterSectionX = ($lineB - $rayB) / ($rayK - $lineK); echo "\$pointInterSectionX = ($lineB - $rayB) / ($rayK - $lineK) = $pointInterSectionX;"; $pointInterSectionY = $lineK * $itemPointAr[0] + $lineB;echo 555555; echo "Сравление по X ($pointLastX < $pointInterSectionX) and ($pointItemAr[0] >= $pointInterSectionX)\n"; echo "Сравнение по Y: ($pointLastX >= $pointInterSectionX) and ($pointItemAr[0] < $pointInterSectionX)\n"; if (($pointLastX < $pointInterSectionX) and ($pointItemAr[0] >= $pointInterSectionX)) {$count++;echo 99999;} elseif (($pointLastX >= $pointInterSectionX) and ($pointItemAr[0] < $pointInterSectionX)) {$count--;echo 777777;} } } echo "Line direction x: ";if ($lineDirectionX) {echo "true";} else {echo "false";}echo "\n"; echo "Line direction y: ";if ($lineDirectionY) {echo "true";} else {echo "false";}echo "\n"; echo "Line k: ";if ($lineK === true) {echo "true";} elseif ($lineK === false) {echo "false";} else {echo $lineK;}echo "\n"; echo "Line b: $lineB\n"; } else {echo "за пределами $pointLastX - ${pointAr[0]} : $pointLastY - ${pointAr[1]}\n";var_dump($rayDirectionX);var_dump($rayDirectionY);if ($pointItemAr[0] >= $pointAr[0]) {echo "Да";}if ($pointLastX >= $pointAr[0]) {echo "Да";}echo "!";if ($pointItemAr[1] >= $pointAr[1]) {echo "Да";}} $pointLastX = $pointItemAr[0]; $pointLastY = $pointItemAr[1]; } else { echo "совпадение ${pointItemAr[0]}\n"; } echo "[count:$keyyy:$count]"; } if ($count) {return true;} echo "[count:$count]AAAAAAAAAAA"; } } var_dump($pointsAr); return false; } $coordinates = "[[55.76086677080351,37.63324240852858],[55.7688028236163,37.63581732918288],[55.77518920008432,37.63942221809891],[55.78331579591449,37.642340461507104],[55.7896030651802,37.6361606519368],[55.79086039675687,37.622256080403595],[55.79028009493986,37.61281470467116],[55.78573409699247,37.60543326546218],[55.77818849907833,37.60594824959305],[55.773254045453605,37.610926429524675],[55.76425430885205,37.61470297981765],[55.761350722905306,37.61298636604813],[55.763189685883496,37.59856681038407],[55.767157677666916,37.58105734993484],[55.77025436508524,37.56921271492507],[55.77228643195437,37.553419868245385],[55.77306052468359,37.5350521009114],[55.76522212258233,37.52698401619461],[55.75331633700064,37.52698401619461],[55.74954056959417,37.55547980476882],[55.74954056959417,37.57007102180983],[55.75079919950975,37.591185371175065],[55.75476845750829,37.60955313850905],[55.755155680474594,37.618994514241486],[55.750315115906794,37.61641959358719],[55.744699305236836,37.613673011555946],[55.73937321761728,37.6119563977864],[55.73414325768277,37.6119563977864],[55.73104369005697,37.62191275764968],[55.73094682458611,37.634615699544206],[55.7359835090206,37.65040854622389],[55.74479613643628,37.65229682137038],[55.750218298462286,37.64405707527664],[55.75641412845275,37.6335857312825],[55.75651093045438,37.64852027107743],[55.75467165116348,37.65727500130203],[55.75196097554392,37.66723136116531],[55.75089601550643,37.68285254646805],[55.74983102627121,37.698302070393815],[55.75060556679248,37.71220664192702],[55.75641412845275,37.727656165852814],[55.76241539629778,37.728857795491486],[55.76899636561494,37.72628287483719],[55.77344756525872,37.71443823982742],[55.774318392441046,37.691435615315704],[55.772867002948665,37.66774634529617],[55.77247995658408,37.658476630940704],[55.77364108409892,37.64731864143875]]"; $coordinates = json_decode($coordinates,true); var_dump(aaa3($coordinates,array(55.77,37.633)));