# Maths of elliptical orbits

I have a simulation of the solar system that currently gives me circular orbits. I'm not 100% sure where I've limited my simulation to this, but probably it starts when I use $$v=\frac{2 \pi r}{T}$$ to calculate the orbital velocity. I now want my orbits to be elliptical, but I honestly have no idea how to do that! Presumably I have to change my input velocity. There are several velocities to choose from on the NASA planet factsheets, and I don't know if I can just set the max. velocity to be the velocity at the furthest point from the sun?

You can use the orbiltal equation
$$r=\frac{k}{1+\epsilon \cos\theta}$$

where $(r,\theta)$ are the polar coordinates, $k$ is a constant and $\epsilon$ is the eccentricity

So, $$\dot{r}=\frac{\epsilon k \sin \theta}{(1+\epsilon \cos \theta)^2}\dot{\theta}$$

$mr^2\dot{\theta}=L$

$L$ is the angular momentum and is a constant, So

$$\dot{r}=\frac{\epsilon k \sin \theta}{(1+\epsilon \cos \theta)^2}\frac{L^2}{mr^2}$$

The total orbital velocity of the body,

$v^2=r^2\dot{\theta}^2+\dot{r}^2$

$$v^2=\frac{L^2}{m^2 r^2}+\dot{r}^2$$

The formula $v=\frac{2\pi r}{T}$ holds for any periodic motion, circular or not, with the one requirement that the speed is constant. It seems that you wish to have elliptical orbits with non-constant speeds, which is the case for elliptical space orbits, so this expression is not usable.

In a typical elliptical orbit observed in space for example, the maximum velocity is when the object is closest to the planet/star. Think of it as a rubberband swing; it moves slower at the longer stretches and faster closer to the source of the pull.

Modelling of elliptical paths is not at all as easy as circular paths. You could do a force calculation though, by finding the masses of the planets. The formula for gravitiatonal force as well as Newton's 2nd law are tying the pull with the motion:

$$F_g=G\frac{m_1m_2}{r^2}\quad\quad\quad\quad\sum F=ma$$

You will have to consider a 2D-scenario with acceleration in two coordinate directions.

On Wikipedia https://en.wikipedia.org/wiki/Orbital_mechanics#Elliptical_orbits there are many possible equations for elliptical paths that you migth want to use. It depends on how much information about the path you already know (like major and minor axis lengths)