Mathematically calculate if a Planet is in apparent Retrograde motion I am trying to find out if a planet is in an apparent retrograde motion with respect to the earth at any given point in time. Given the time in Julian days.
I already have the geocentric and heliocentric coordinates and velocities of the planet using the JPL ephimeris, but not sure of what mathematical formula to use to identify the retrograde motion.
I read this article "Mathematically calculate if a Planet is in Retrograde" which had a similar question but I am not sure of
1) Is the answer correct as it has not been marked as correct?
2) How to represent earth in the XY plane only when it has XYZ planes and why do we even need to do that? Cann't we just use the heliocentric equitorial plane which I think is the same as the one used by NASA JPL ephimeris.
 A: *

*I'm assuming from the upvotes that my answer was correct but incomplete. Working out the equations for orbits that are not in the same plane would have taken far too much time for too little gain.

*The coordinate system I used was a heliocentric ecliptic coordinate system. This simplifies the comparison of orbits since most of the planets orbit the sun very close to the ecliptic plane. Due to Earth's tilt, using an equatorial coordinate system would be more mathematically difficult since the relative motion of the planets would be three-dimensional.
As for the rest of the answer, the idea is to calculate the angle of a ray from Earth through the other planet, as this represents the position of the planet in the sky with respect to the fixed stars. When the movement of this line reverses direction, the other planet is entering or leaving retrograde motion.
For the purposes of determining when retrograde motion occurs, motion of the planets perpendicular to the ecliptic plane does not matter. Below are two pictures of time-lapsed retrograde motion of Mars. Whether the motion is in a loop or an S-curve, what determines when retrograde motion happens is when the component of the vector joining two planets that is parallel to the ecliptic reverses its direction of rotation. In the pictures below, that corresponds to the points of reversal in the tilted horizontal motion. This is why I ignore the Z-component of the planet's motion.
https://apod.nasa.gov/apod/ap100613.html

http://apod.nasa.gov/apod/ap160915.html

