I have a list with ellipse objects with the parameters (Point Begin, Point End, Color c). Now I want to ensure when I click somewhere if I did hit an ellipse.
I also do this with rectangles which already works and looks something like this:
case 3: // Rectanglefill
return p.X >= Begin.X && p.X <= End.X && p.Y >= Begin.Y && p.Y <= End.Y;
In this method I only want to return the bool True if I have a hit and False if the mouse click didn’t hit something.
Now for the ellipse I already have this:
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);
But this doesn’t work.
Your equation is Ok, you just have to put
<1(or<=1if you want to include the points on the ellipse) instead of>1