-1

I'm trying to calculate whether or not a specific X,Y position lies within an ellipse in C#.

The available variables to work with are: X (the X I want to check) Y (the Y I want to check) The width of the ellipse The height of the ellipse The x-center of the ellipse (as the ellipse is drawn somehwere on a screen, it has to be calculated). The y-center of the ellipse (again, random position, so this had to be calculated.

So far I tried basic mathematics, but those wouldn't get me as far as I needed.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rik_S
  • 381
  • 4
  • 13
  • 3
    Why basic math failed? There is ellipse equation to which you should be able to use you x and y to calculate if the point is on or inside of ellipse or outside of it. Why is that a problem? – Jarek Apr 19 '13 at 13:42
  • It failed becuase of human error of course. A misscalculation in determining where the ellipse was on the screen. I feel such an idiot sometimes. – Rik_S Apr 20 '13 at 12:07

2 Answers2

1

Try yourEllipse.RenderedGeometry.StrokeContains(Pen pen, Point point) method

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
1

Is the ellipse horizontal, or rotated?

For horizontal ellipse with center (xc,yc) and radii rx and ry all the points inside obey the equation

((x-xc)/rx)^2 + ((y-yc)/ry)^2 <= 1

So just check your point (x,y) against the equation above.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133