如何检查Point是否在Ellipse内?当我像这样绘制椭圆时:
imageellipse($image, 300, 460, 400, 590, $col_ellipse);
如何确定点x = 100 y = 400是否在我的椭圆内?
结果:
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;
}
答案 0 :(得分:2)
感谢@Jordi Nebot对数学表格的帮助。我的结果:
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;
}