If I have coordinates of center point of circle, circle radius and also coordinates of the point that need to be check if a point lies inside or on the boundary of the Circle.
- $circle_x and $circle_y => center point latitude and longitude of the circle
- $rad => radius(Meter) of the circle
- $x and $y => latitude and longitude of the point that need to be check
I have tried 2 ways,
public function pointInCircle($circle_x, $circle_y, $rad, $x, $y)
{
$dx = abs($x - $circle_x);
$dy = abs($y - $circle_y);
$R = $rad;
if ($dx + $dy <= $R) {
return "inside";
} else if ($dx > $R) {
return "outside";
} else if ($dy > $R) {
return "outside";
} else if ($dx ^ 2 + $dy ^ 2 <= $R ^ 2) {
return "inside";
} else {
return "outside";
}
}
Second method is,
public function pointInCircle($circle_x, $circle_y, $rad, $x, $y)
{
if ((($x - $circle_x) * ($x - $circle_x) + ($y - $circle_y) * ($y - $circle_y)) <= ($rad * $rad)){
return "inside";
} else {
return "outside";
}
}
But above 2 methods couldn't provide correct result, please help to find if provided point lies inside or on the boundary of the Circle using PHP.