Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top