Points within an ellipse on the globe I'm interested in finding the equation that will tell me if a given geographical coordinate (lat1, lon1) is within an ellipse centered on a another coordinate (lat2, lon2) with a given semi-major axis (a) and a semi-minor axis (b) and a rotation (rot) in radians.
I've found equations for dealing with points inside of an unrotated ellipse, but none that take into account the curve of the Earth, e.g., using the haversine formula, nor any that involve a rotation.
I thought I could puzzle through this, but I've hit the limits of my own geometry... the goal is to turn this into a SQL query, for whatever that is worth.
 A: If the centre $C$ of the ellipse has longitude $\phi$ and colatitude $\theta$ then its coordinates are
$$C=R(\sin\theta\cos\phi,\sin\theta\sin\phi,\cos\theta),$$
where $R=\ $radius of the sphere.
The foci $F_1$, $F_2$ of the ellipse are located on the major axis, at a distance $c=\sqrt{a^2-b^2}$ from the centre. If the major axis is rotated of an angle $\alpha$ (counterclockwise) with respect to the North direction, then the coordinates of the foci are:
$$
F_{1,2}=R
\pmatrix{\pm\cos \alpha \sin \gamma \cos \phi \cos \theta\mp\sin \alpha \sin \gamma \sin \phi+\cos \gamma \cos \phi \sin \theta \\
\pm\cos \alpha \sin \gamma \sin\phi \cos \theta\pm\sin \alpha \sin \gamma \cos \phi+\cos \gamma \sin \phi \sin \theta \\
\cos \gamma \cos \theta\mp\cos \alpha \sin \gamma \sin \theta},
$$
where $\gamma=c/R$ is the central angle corresponding to the distance between the centre and a focus.
To check if a point $P$ on the sphere is inside the ellipse, compute its distances $d_1$, $d_2$ from the foci and check if $d_1+d_2\le2a$.
