Planets never reverse. Earth overtakes (or is overtaken by) them on an inner or outer track, so from Earth the planet seems to slow, stop, drift backwards and stop again. Orbits here are real Kepler ellipses with inclinations.
Steps half a day, finds every retrograde interval and every Sun-Earth-planet alignment, and compares the averages with the synodic-period formula.
The science
Orbits. Each planet follows a Kepler ellipse from the JPL approximate J2000 elements (a, e, i, L, longitude of perihelion, longitude of node, mean-longitude rate). Mean anomaly M = L − ϖ; Kepler's equation M = E − e sin E is solved by Newton iteration; position in the orbital plane x = a(cos E − e), y = a√(1−e²) sin E is rotated by ω, i and Ω to ecliptic coordinates.
Sky. Geocentric vector d = P_planet − P_Earth; ecliptic longitude λ = atan2(dy, dx), latitude β = atan2(dz, √(dx²+dy²)). Retrograde means dλ/dt < 0, estimated from λ one day later minus one day earlier.
Synodic period. 1/S = |1/PEarth − 1/Pplanet|: Mars 779.9 d, Jupiter 398.9 d, Venus 583.9 d. Retrograde loops repeat once per synodic period. Kepler's third law P² = a³ (years, AU) links period and distance.
Why a loop, not a line. Near opposition an outer planet is closest, so Earth's faster motion shows up most strongly as parallax and outweighs the planet's own eastward drift. The planet's orbital inclination turns the back-and-forth into a loop in latitude.
Simplifications. Elements are held fixed at J2000 values (no secular drift, no perturbations between planets), Earth stands for the Earth-Moon barycentre, positions are geometric (no light-time, aberration or precession), and the date axis is dynamical time. Dates can be off from published almanacs by days, far from J2000 by more. Textbook retrograde lengths (Mars about 72 d, Jupiter about 121 d) are typical values and vary with eccentricity. Models built with Blender, scene by Three.js.