1

我有一个带有参数(点开始、点结束、颜色 c)的椭圆对象列表。现在我想确保当我点击某个地方时,如果我确实击中了一个椭圆。

我也用已经工作的矩形来做这个,看起来像这样:

 case 3: // Rectanglefill
        return p.X >= Begin.X && p.X <= End.X && p.Y >= Begin.Y && p.Y <= End.Y;

在这种方法中,我只想在点击时返回布尔 True,如果鼠标点击没有击中某些东西,则返回 False。

现在对于椭圆我已经有了这个:

case 4: // Ellipsfill
/*  int radiusx = Math.Abs(End.X - Begin.X) / 2;
    int radiusy = Math.Abs(End.Y - Begin.Y) / 2;
    int midpointx = (Begin.X + End.X) / 2;
    int midpointy = (Begin.Y + End.Y) / 2;

return ((Math.Pow((p.X -midpointx) / radiusx, 2) + Math.Pow((p.Y - midpointy) / radiusy, 2)) > 1);

但这不起作用。

4

1 回答 1

0

你的方程是好的,你只需要放<1(或者<=1如果你想包括椭圆上的点)而不是>1

case 4: // Ellipsfill
    double radiusx = Math.Abs((double)End.X - (double)Begin.X) / 2.0;
    double radiusy = Math.Abs((double)End.Y - (double)Begin.Y) / 2.0;
    double midpointx = ((double)Begin.X + (double)End.X) / 2.0;
    double midpointy = ((double)Begin.Y + (double)End.Y) / 2.0;

return ((Math.Pow((p.X -midpointx) / radiusx, 2) + Math.Pow((p.Y - midpointy) / radiusy, 2)) < 1.0);
于 2012-11-06T22:13:26.560 回答