Rotating ellipse equation, solve for $x$

conic sectionsgeometryrotations

I want to get the coordinates of the intersection of an ellipse and a line.

The line has the equation:
$$y=\frac{p-y_1}{q-x_1}\,(x-x_1)+y_1. $$

The numbers $x_1, p, y_1, q$ represent the coordinates of two points: $A(x_1, y_1)$ and $S(p, q).$

The ellipse has the equation:
$$\left( \frac{ (x – p) \cos(\alpha) – (y – q) \sin(\alpha) }{a} \right)^{\!2} + \left( \frac{ (x – p) \sin(\alpha) + (y – q) \cos(\alpha) }{b} \right)^{\!2} = 1 .$$

Numbers $p, q$ represent the center of the ellipse $S(p, q), a$ is half of the ellipses' width, $b$ is half of the ellipses' height and $\alpha$ is the angle of rotation.

Basically I am trying to test if a dot is intersecting the ellipse by first calculating the line of the dot and ellipses' center then calculating the intersection of the ellipse and the line and finally checking if the distance between the dot and center is lower or equal than the distance between ellipses' center and the intersection.

Now this is really simple to do on paper but I am doing this for a game I am programming and I don't have any library that can solve an equation so I need a formula for the $x$ or $y$ coordinate of the intersection.

Best Answer

The point is inside or on the ellipse iff

$$\left( \frac{ (x_1 - p) \cos(\alpha) - (y_1 - q) \sin(\alpha) }{a} \right)^{\!2} + \left( \frac{ (x_1 - p) \sin(\alpha) + (y_1 - q) \cos(\alpha) }{b} \right)^{\!2}\le 1 .$$

Don't use a line !