Finding, если точка лежит внутри многоугольника или нет, что будет сделано в обновлении
//this assumes that the orientation of your polygon is
//http://en.wikipedia.org/wiki/File:Pentagon.svg
$pass=1;
function filter($init, $final, $center)
{
if(($final['a']['x']-$init['x'])*($center['y']-$init['y'])-($final['a']['y'] - $init['y'])*($center['x']-$init['x']) > 0)
return $final['a'];
else
return $final['b'];
}
function getNextPoint($init, $center, $distance, $slope)
{
global $pass;
$final['a']['x'] = $init['x']+$distance/sqrt(1+tan($slope)*tan($slope));
$final['a']['y'] = $init['y']+(tan($slope)*$distance)/sqrt(1+tan($slope)*tan($slope));
$final['b']['x'] = $init['x']-$distance/sqrt(1+tan($slope)*tan($slope));
$final['b']['y'] = $init['y']-(tan($slope)*$distance)/sqrt(1+tan($slope)*tan($slope));
echo "<br/><br/>";
echo "Pass: $pass <br/>";
echo "Slope: ".$slope."<br/>";
if($pass == 1){
$point = $final['b'];
$distance = $distance*2*sin(pi()/5);
$slope = 0;
}
else{
$point = filter($init, $final, $center);
$slope = $slope+pi()/2.5;
}
echo "Position: ";
print_r($point);
echo "<br/>";
echo "Distance : ".distance($init['x'], $init['y'], $point['x'], $point['y']);
if($pass == 7){
return $point;
}
else{
//echo "x: ".($point['x'])." y: ".($point['y'])." <br/>";
$pass++;
getNextPoint($point, $center, $distance, $slope);
}
//echo "x: ".($point['x'])." y: ".($point['y'])." <br/>";
}
function polygon($vertices=5, $centerX=10, $centerY=10, $radius=5)
{
$internalangle = ($vertices-2)*pi()/$vertices;
$slope = pi()+($internalangle)/2;
$init['x'] = 10;
$init['y'] = 10;
getNextPoint($init, $init, 5, $slope);
}
polygon();
/*
function getx($slope, $x1, $y1, $y)
{
return (($y-$y1)/$slope+$x1);
}
function gety($slope, $x1, $y1, $x)
{
return ($slope*($x-$x1)+$y1);
}
*/
function distance($initx, $inity, $finalx, $finaly)
{
return sqrt(($initx-$finalx)*($initx-$finalx)+($inity-$finaly)*($inity-$finaly));
}
function getslope($final, $init)
{
return atan(($final['y']-$init['y'])/($final['x']-$init['x']))*180/pi();
}
Что это нужно делать с PHP или MySQL? –
Данные многоугольника должны храниться в базе данных mysql, и то же самое нужно получить с помощью php, чтобы получить вершины и найти, лежит ли внутри него точка. Я добавил больше подробностей к моему вопросу. –
http://en.wikipedia.org/wiki/Point_in_polygon – Jacob