I was trying to simulate Gravitational Orbits using Newtonian Gravitation. I did not use NDSolve[]
but instead used finite differences; coded myself. The code for which is as follows:
M = 1; G = 1;h = 0.1; T = 1; n = T/h; (*steps*)
NewtonGrav[{vx_, vy_, vz_, x_, y_, z_}] :=
{vx + (-G M x)/Sqrt[x^2 + y^2 + z^2]*h,
vy + (-G M y)/Sqrt[x^2 + y^2 + z^2]*h,
vz + (-G M z)/Sqrt[x^2 + y^2 + z^2]*h,
x + vx*h, y + vy*h, z + vz*h}
DataNewton = NestList[NewtonGrav, {1, 1, 1, 1, 1, -1}, IntegerPart[n]];
DataPlot = Table[Drop[DataNewton[[i]], 3], {i, 1, Length[DataNewton]}]
The output of the above code is the array $ \{{x[t],y[t],z[t]}\}$ for discreet $t$ values.
{{1, 1, -1}, {1.1, 1.1, -0.9}, {1.19423, 1.19423, -0.794226},
{1.28233, 1.28233, -0.683445}, {1.36404, 1.36404, -0.568408},
{1.43913, 1.43913, -0.449845}, {1.50744, 1.50744, -0.328455},
{1.56884, 1.56884, -0.204907}, {1.62326, 1.62326, -0.0798366},
{1.67063, 1.67063, 0.0461538}, {1.71094, 1.71094, 0.172492}}
I want to plot this data. But, I find no function that helps me do that properly. What I want is to plot all these points in 3-dimensional space and join all these with a line connecting the consecutive points in time. I am using a "brute force" method to demonstrate what I want.
Show[Graphics3D[Point[DataPlot[[1]]]],
Graphics3D[Point[DataPlot[[2]]]], Graphics3D[Point[DataPlot[[3]]]],
Graphics3D[Point[DataPlot[[4]]]], Graphics3D[Point[DataPlot[[5]]]],
Graphics3D[Point[DataPlot[[6]]]], Graphics3D[Point[DataPlot[[7]]]],
Graphics3D[Point[DataPlot[[8]]]], Graphics3D[Point[DataPlot[[9]]]],
Graphics3D[Point[DataPlot[[10]]]], Graphics3D[Point[DataPlot[[11]]]]]
Whose output is as follows. These are all the calculated points of trajectory.
Now, I want to join these points. Code for which would be.
Show[Graphics3D[Line[{DataPlot[[2]], DataPlot[[1]]}]] ,
Graphics3D[Line[{DataPlot[[3]], DataPlot[[2]]}]] ,
Graphics3D[Line[{DataPlot[[4]], DataPlot[[3]]}]] ,
Graphics3D[Line[{DataPlot[[5]], DataPlot[[4]]}]] ,
Graphics3D[Line[{DataPlot[[6]], DataPlot[[5]]}]] ,
Graphics3D[Line[{DataPlot[[7]], DataPlot[[6]]}]] ,
Graphics3D[Line[{DataPlot[[8]], DataPlot[[7]]}]] ,
Graphics3D[Line[{DataPlot[[9]], DataPlot[[8]]}]] ,
Graphics3D[Line[{DataPlot[[10]], DataPlot[[9]]}]],
Graphics3D[Line[{DataPlot[[11]], DataPlot[[10]]}]]]
I want the final image as a direct output plot of the array I have in such a way that I can use manipulate to simulate the trajectory in time. Is there a function to do that? I have tried Plot3D[]
, ListPointPlot3D[]
, ParametricPlot3D[]
, ListPlot3D[]
.
The command ParametricPlot3D[]
was the best choice among all but either it is not possible to use in the way I have written the code or I don't know how to do it. All other commands plotted out a surface plot (discrete or continuous). So, How to do it?