I'm trying to find out how to calculate the initial velocity needed to keep a spacecraft in a circular orbit around the Earth given its initial position and an initial angle theta in a Cartesian coordinate system. I know the formula for the magnitude of a circular orbit is $v_{\mathrm{circular}} = \sqrt{GM/r_{\mathrm{orbit}}}$ but this only works nicely as it is (i.e. in its magnitude form) if the orbital radius vector makes an angle of 0, 90 or 270 degrees in a Cartesian coordinate system. What I want to do is be able to use the formula for any angle $\theta$.
As an example, let's say I have a spacecraft at a radius of 300000 meters above the Earth's surface and its radius vector makes an angle of 45 degrees in an x-y Cartesian coordinate system. Then we have $r = r_{\mathrm{earth}} + 300000$, whereby $r_x = r \cos(45^\circ)$ and $r_y = r \sin(45^\circ)$. Here's a little picture I made to better understand the problem:
If theta = 45 degrees, then I get a nice circular orbit, but any other value of theta gives me very undesirable results (i.e. the spacecraft crashes into the planet or flies of into the cosmos)
Does anyone know what I'm doing wrong?
G = 6.672*10^-11;
m[1] = AstronomicalData["Earth", "Mass"];
tmax = 20000;
r[1] = AstronomicalData["Earth", "Radius"];
rx = (r[1] + 300000 ) Cos[45 Degree]
ry = (r[1] + 300000 ) Sin[45 Degree]
vx = Sqrt[(G m[1])/(r[1] + 300000)] Cos[45 Degree]
vy = Sqrt[(G m[1])/(r[1] + 300000)] Sin[45 Degree]
soln = NDSolve[{
x''[t] == -((G m[1] x[t])/(x[t]^2 + y[t]^2)^(3/2)),
y''[t] == -((G m[1] y[t])/(x[t]^2 + y[t]^2)^(3/2)),
x[0] == rx, y[0] == ry,
x'[0] == vx, y'[0] == -vy}, {x[t],
y[t]}, {t, 0, tmax} , MaxSteps -> 1000000,
Method -> "StiffnessSwitching"]
Show[ParametricPlot[Evaluate[{x[t], y[t]} /. soln], {t, 0, tmax},
AxesLabel -> {x, y}, PlotStyle -> Automatic, PlotRange -> Full,
ImageSize -> Large], Graphics[{Green, Disk[{0, 0}, r[1]]}]]