1
$\begingroup$

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.

Ellipse_Collison

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 ?

$\endgroup$
  • $\begingroup$ What if the ellipse is a circle ? $\endgroup$ – reuns Jan 26 '17 at 12:04
  • $\begingroup$ 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. $\endgroup$ – Itay.V Jan 26 '17 at 12:07
  • $\begingroup$ Your ellipse is just a stretched circle $\endgroup$ – reuns Jan 26 '17 at 12:08
2
$\begingroup$

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|$

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.