# Object slowest at periapsis - despite correct position calculation

I'm coding up a simulation of celestial bodies using patched conics. At the moment I'm stuck with calculating the velocity of the object in the perifocal frame.

For the position I'm simply using the orbit equation

$$r = \frac{h^2}{\mu}\frac{1}{1 + e\cos{v}}$$

where $$h$$ is the angular momentum, $$\mu$$ is the standard gravitational parameter, $$e$$ is eccentricity, $$v$$ is true anomaly.

I then take the cosine and sine of $$v$$ to get the exact point in the perifocal frame, so $$p = r\sin v$$ $$q = r\cos v$$

It makes sense to me then that $$\frac{dp}{dv}$$ and $$\frac{dq}{dv}$$ would give me the velocity components.

So I take the derivative (using Wolfram Alpha) and arrive at the following

$$\frac{dr\sin v}{dv} = \frac{h^2(\cos v + e)}{\mu(1 + e \cos v)^2}$$ $$\frac{dr\cos v}{dv} = -\frac{h^2\sin v}{\mu(1 + e\cos v)^2}$$

which simplify to

$$\frac{dr\sin v}{dv} = \frac{r (\cos v + e)}{1 + e\cos v}$$

$$\frac{dr\cos v}{dv} = -\frac{r \sin v}{1 + e\cos v}$$

But putting these to use the positions appear to work as expected. But velocity is the lowest at the periapsis and highest at the apoapsis. Which I know shouldn't be the case.

The same behaviour appears if I just approximate the velocity as $$p(v) - p(v + 0.001)$$

Is there anything wrong with my calculations or assumptions?

• The equation you've used only gives you information about the shape of the orbit. It looks like you're assuming a constant angular vellocity, which is definitely not the case in non-circular orbits. Nov 23, 2023 at 23:08
• You may find this helpful: physics.stackexchange.com/a/675868/123208 & physics.stackexchange.com/a/748130/123208 which have the vis-viva equation in terms of true anomaly, and some other related stuff about angular velocity and specific angular momentum. Nov 24, 2023 at 1:28

As uhoh said, the velocity is the derivative of the position w.r.t. to time, not true anomaly. I.e., if we denote time by $$t$$, the components of the velocity vector are $$\left(\frac{dp}{dt}, \frac{dq}{dt}\right) = \left(\frac{dp}{dv}\frac{dv}{dt}, \frac{dq}{dv}\frac{dv}{dt}\right)$$. Fortunately, $$\frac{dv}{dt}$$ is just the angular speed, equal to $$\frac{h}{r^2}$$ (because the specific angular momentum $$h$$ is equal to $$r\text{v}_\perp$$, where $$\text{v}_\perp$$ is the transversal speed, and $$\text{v}_\perp = r\frac{dv}{dt}$$).

So the actual velocity components are $$\frac{dp}{dt} = \frac{r (\cos v + e)}{1 + e\cos v}\frac{h}{r^2} = \frac{\mu}{h} (\cos v + e)$$ and $$\frac{dq}{dt} = -\frac{r \sin v}{1 + e\cos v}\frac{h}{r^2} = -\frac{\mu}{h} \sin v.$$

• Thanks! This helped a lot! Nov 30, 2023 at 19:32

If I understand correctly, your $$p, q$$ are essentially cartesian coordinates, and you're trying to get the velocity components in those two orthogonal directions.

However, you're taking the derivative with respect to true anomaly $$v$$, and $$v$$ does not increase linearly with time for non-circular orbits. It's mean anomaly that does that. While there is a transcendental relationship between the two, they are not interchangeable.

Things like $$r(t)$$ and $$v(t)$$ have no simple solution that you can just differentiate to get velocity.

However you have two other ways to get velocity.

1. The vis-viva equation will give you speed v (not your $$v$$) as a direct function of $$r$$ (via conservation laws) and you can apply that speed tangent to the ellipse to get the velocity vector.

$$\text{v}^2 = GM \left(\frac{2}{r} - \frac{1}{a} \right)$$

1. Luckily for us while $$r(t)$$ and $$v(t)$$ don't have simple solutions, their inverse $$t(r)$$ and $$t(v)$$ do! See:
• $\frac{dv}{dt}$ (i.e., the angular speed) is $\frac{h}{r^2}$. The OP just needs to multiply the answer by this to get the correct velocity components. Nov 24, 2023 at 10:42
• @Litho I don't know what $h$ is and I'm not an orbital mechanic. Please consider writing a short answer post so that folks will see it. Thanks!
– uhoh
Nov 24, 2023 at 11:36