PHP:检查椭圆内的点/坐标

时间:2017-04-04 14:03:52

标签: php math

如何检查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;
}

1 个答案:

答案 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;
}