# Point-Ellipse collision test.

O.k, so basically i am writing some C++ program and I've encountered some problem. i need to check if a given Point $P$ is inside Ellipse or not.

So lets say points $(X_0,Y_0),(X_1,Y_1),P_0,P_1$ what i need to test is if the point $P_0$ (or $P_1$ in other occasion) is inside the ellipse or not. We can assume that the ellipse would be placed inside some rectangle with given points $(X_0,Y_0),(X_1,Y_1)$ and the rectangle's edges would be parallel to $X,Y$ axis (The ellipse wont be rotated but the height could be bigger than the width and the opposite).

any idea of how can i implement it ?

• What if the ellipse is a circle ? – reuns Jan 26 '17 at 12:04
• im checking distance in that situation, i've fixed that, i have 2 kinds of shapes, circle and ellipse. for circle i've checked the radius and the distance of the point from the center. – Itay.V Jan 26 '17 at 12:07
• Your ellipse is just a stretched circle – reuns Jan 26 '17 at 12:08

Use the ellipse equation. A point $(x,y)$ is inside the ellipse if $$\frac{(x- m_x)^2}{\sigma_x^2} + \frac{(y- m_y)^2}{\sigma_y^2} < 1$$

The center of the ellipse is given by $(m_x, m_y)$ and the half-diameters are given by $(\sigma_x, \sigma_x)$ and you can read these off easily from your sketch:

$m_x = \frac 12 (x_0 + x_1)$

$m_y = \frac 12 (y_0 + y_1)$

$\sigma_x = \frac 12 |- x_0 + x_1|$

$\sigma_y = \frac 12 |- y_0 + y_1|$

• thanks!! will implement now and update later!! Much appreciated!! – Itay.V Jan 26 '17 at 12:18
• Works Perfectly!!! Thanks!! – Itay.V Jan 26 '17 at 12:55
• Thank you, it does indeed work! – Yuri Brigance Aug 29 '18 at 2:13