I had this same problem several years ago and despite searching for it extensively, I could not find it explicitly spelled-out anywhere, so I had to derive it myself. I am not a physicist and frankly I found the whole thing so frustrating that, as I mentioned in the comments, I added this section to the Wikipedia article so that other people would not have to go through the same thing:
Elliptic orbit From Initial Position and Velocity
An orbit equation defines the path of an orbiting body
$m_2\,\!$ around central body
$m_1\,\!$ relative to
$m_1\,\!$, without specifying position as a function of time (trajectory). If the eccentricity is less than 1 then the equation of motion describes an elliptical orbit. Because Kepler's equation (
$M = E - e \sin E$) has no general closed-form solution for the Eccentric anomaly (
$E$) in terms of the Mean anomaly (M), equations of motion as a function of time also have no closed-form solution (although numerical solutions exist for both).
However, closed-form time-independent (path) equations of an elliptic orbit with respect to a central body can be determined from just an initial position ($\mathbf{r}$) and velocity ($\mathbf{v}$) (and the mass(es)).
For this case it is convenient to use the following assumptions:
- The central body’s position is at the origin and is the primary focus ($\mathbf{F1}$) of the ellipse (alternatively, the center of mass may be used instead if the orbiting body has a significant mass)
- The central body’s mass (m1) is known
- The orbiting body’s initial position($\mathbf{r}$) and velocity($\mathbf{v}$) are known
- The ellipse lies within the XY-plane
The fourth assumption can be made without loss of generality because any three points (or vectors) must lie within a common plane. Under these assumptions the second focus (sometimes called the “empty” focus) must also lie within the XY-plane: $\mathbf{F2} = \left(f_x,f_y\right)$ .
Using Vectors
The general equation of an ellipse under these assumptions using vectors is:
$$ |\mathbf{F2} - \mathbf{p}| + |\mathbf{p}| = 2a \qquad\mid z=0$$
where:
- $a\,\!$ is the length of the semi-major axis.
- $\mathbf{F2} = \left(f_x,f_y\right)$ is the second (“empty”) focus.
- $\mathbf{p} = \left(x,y\right)$ is any (x,y) value satisfying the equation.
The semi-major axis length (a) can be calculated as:
$$a = \frac{\mu |\mathbf{r}|}{2\mu - |\mathbf{r}| \mathbf{v}^2}$$
where $\mu\ = Gm_1$ is the standard gravitational parameter.
The empty focus ($\mathbf{F2} = \left(f_x,f_y\right)$) can be found by first determining the Eccentricity vector:
$$\mathbf{e} = \frac{\mathbf{r}}{|\mathbf{r}|} - \frac{\mathbf{v}\times \mathbf{h}}{\mu}$$
Where $\mathbf{h}$ is the specific angular momentum of the orbiting body:
$$\mathbf{h} = \mathbf{r} \times \mathbf{v}$$
Then
$$\mathbf{F2} = -2a\mathbf{e}$$
Using XY Coordinates
This can be done in cartesian coordinates using the following procedure:
The general equation of an ellipse under the assumptions above is:
$$ \sqrt{ \left(f_x - x\right)^2 + \left(f_y - y\right)^2} + \sqrt{ x^2 + y^2 } = 2a \qquad\mid z=0$$
Given:
- the initial position coordinates $r_x, r_y \quad$
- the initial velocity coordinate $v_x, v_y \quad$
- and the gravitational parameter $\mu = Gm_1 \quad$
Then, specific angular momentum:
$$h = r_x v_y - r_y v_x \quad$$
initial distance from F1 (at the origin):
$$r = \sqrt{r_x^2 + r_y^2} \quad$$
the semi-major axis length:
$$a = \frac{\mu r}{2\mu - r \left(v_x^2 + v_y^2 \right)} \quad$$
the Eccentricity vector coordinates:
$$e_x = \frac{r_x}{r} - \frac{h v_y}{\mu} \quad$$
$$e_y = \frac{r_y}{r} + \frac{h v_x}{\mu} \quad$$
Finally, the empty focus coordinates:
$$f_x = - 2 a e_x \quad$$
$$f_y = - 2 a e_y \quad$$
Now the result values $f_x$, $f_y$ and $a$ can be applied to the general ellipse equation above.
If this is for orbits around the earth or any other irregular body then you should keep in mind that the equations above are only valid for systems that can be modelled accurately as 2-body systems with point-masses or concentrically symmetrical masses. A satellite around the earth is actually typically modelled as the fourth body in a 4-body/3-mass (earth, moon, sun) system in 3 dimensions with the earth as an oblate spheroid. You can model it as a 2-body point-mass system in 2 dimensions (with the equations above) but it may not be sufficiently accurate for your purposes.