Member-only story
Kepler’s Laws of Planetary Motion: Verification with a Python Model

Every introductory astronomy course is going to go over Kepler’s laws. These might also be in a classical mechanics or astrophysics course (depending on the focus). These three laws are data-based rules that show the motion of planets around the Sun and are very important for the development of orbital physics.
Let me just point out the coolest part of these laws — Kepler didn’t really use any physics. He just used data to map out the trajectory of planets. It’s kind of crazy how he was able to accomplish this. Check out this excellent 3Blue1Brown video with Terrance Tao explaining how Kepler did this.
So, since these 3 laws are based on empirical data — it’s not so easy to derive them with physics (it’s possible though). Instead, I’m going to build a numerical model for orbital motion and then use this to test the three laws.
Numerical Orbital Model
Suppose I have a planet moving around the Sun in the solar system. Let’s make two important approximations:
- The planet ONLY interacts with the Sun. The other planets have no effect on its motion (I’m looking at you, Jupiter).
- The Sun remains stationary during this orbit.
With that, we can calculate the force on the planet at any given position. Just to make things simpler, let’s put the Sun at the origin. Here’s my planet.

We can calculate the vector force (F) on this planet based on its position. Notice that I’m using the proper form of the universal gravitational force using r-hat (the unit vector in the direction of r).
The problem with the motion of this planet is that unless it has a simple circular orbit, the direction and magnitude of the gravitational force are not constant. We can deal with this by breaking the…