How can I check if a Point is inside a Ellipse? When i draw a Ellipse like the this:
imageellipse($image, 300, 460, 400, 590, $col_ellipse);
How can I find out if the Point x = 100 y = 400 is inside my Ellipse?
RESULT:
function posInside($x, $y, $h, $k, $rx, $ry) {
/*$h = 400; //center x of ellipse
$k = 960; //center y of ellipse
$rx = 400 / 2; //radius x
$ry = 590 / 2; //radius y */
$part1 = pow(($x - $h) / $rx, 2);
$part2 = pow(($y - $k) / $ry, 2);
if($part1 + $part2 <= 1) {
return true;
} else return false;
}
Thank you to @Jordi Nebot for the help with the math form. My Result:
function posInside($x, $y, $h, $k, $rx, $ry) {
/*$h = 400; //center x of ellipse
$k = 960; //center y of ellipse
$rx = 400 / 2; //radius x
$ry = 590 / 2; //radius y */
$part1 = pow(($x - $h) / $rx, 2);
$part2 = pow(($y - $k) / $ry, 2);
if($part1 + $part2 <= 1) {
return true;
} else return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.