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 ?

  • 0
    What if the ellipse is a circle ?2017-01-26
  • 0
    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.2017-01-26
  • 0
    Your ellipse is just a stretched circle2017-01-26

1 Answers 1

2

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

  • 0
    thanks!! will implement now and update later!! Much appreciated!!2017-01-26
  • 0
    Works Perfectly!!! Thanks!!2017-01-26
  • 0
    Thank you, it does indeed work!2018-08-29