<p>Sure, these parameters all fall out of <a href="https://en.wikipedia.org/wiki/Specific_orbital_energy" rel="nofollow noreferrer">orbital energy</a>:</p>
<p><span class="math-container">$$E=\frac{|\vec{v}|^2}{2}-\frac{\mu}{|\vec{r}|}$$</span>
<span class="math-container">$$E=-\frac{1}{2}\frac{\mu^2}{|\vec{h}|^2}(1-e^2)$$</span>
<span class="math-container">$$E=-\frac{\mu}{2a}$$</span></p>
<p>where <span class="math-container">$\vec{v}$</span> is the velocity vector, <span class="math-container">$\vec{r}$</span> is the position vector, <span class="math-container">$\vec{h}=\vec{r} \times \vec{v}$</span> is the specific relative angular momentum, and <span class="math-container">$\mu$</span> is the standard gravitational parameter, <span class="math-container">$e$</span> is the eccentricity, and <span class="math-container">$a$</span> is the semi-major axis.  Calculate <span class="math-container">$E$</span> in the first equation, solve and calculate <span class="math-container">$e$</span> in the second equation, solve and calculate <span class="math-container">$a$</span> in the third equation.</p>
<p>Calculate the <a href="https://en.wikipedia.org/wiki/Semi-major_and_semi-minor_axes" rel="nofollow noreferrer">semi-minor axis</a> <span class="math-container">$b$</span> with <span class="math-container">$b=a\sqrt{1-e^2}$</span>.</p>

CC BY-SA 4.0
2022-06-03T06:40:22.230Z
Note that if we wish to express ourselves rigorously, we should say:
...where v is the modulus of the velocity vector, r is the modulus of the position vector, $h=\vert r \times v \vert$ is the modulus of the specific angular momentum...
Albert
CC BY-SA 4.0
2022-06-03T16:30:27.357Z
@Albert This answer is just a "back of the napkin", but  I added some vector notation to clarify.
Connor Garcia
CC BY-SA 4.0
2022-06-02T21:46:11.687Z
2022-06-03T16:26:49.380Z
2022-06-03T16:26:49.380Z
Connor Garcia
<p>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 <a href="https://en.wikipedia.org/wiki/Elliptic_orbit#From_Initial_Position_and_Velocity" rel="nofollow noreferrer">this section</a> to the Wikipedia article so that other people would not have to go through the same thing:</p>
<h1>Elliptic orbit From Initial Position and Velocity</h1>
An orbit equation defines the path of an orbiting body <span class="math-container">$m_2\,\!$</span> around central body <span class="math-container">$m_1\,\!$</span> relative to <span class="math-container">$m_1\,\!$</span>, 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 (<span class="math-container">$M = E - e \sin E$</span>) has no general closed-form solution for the Eccentric anomaly (<span class="math-container">$E$</span>) 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).
<p>However, closed-form time-<em>independent</em> (path) equations of an elliptic orbit with respect to a central body <em>can</em> be determined from just an initial position (<span class="math-container">$\mathbf{r}$</span>) and velocity (<span class="math-container">$\mathbf{v}$</span>) (and the mass(es)).</p>
<p>For this case it is convenient to use the following assumptions:</p>
<ol>
<li>The central body’s position is at the origin and is the primary focus (<span class="math-container">$\mathbf{F1}$</span>) of the ellipse (alternatively, the center of mass may be used instead if the orbiting body has a significant mass)</li>
<li>The central body’s mass (m1) is known</li>
<li>The orbiting body’s initial position(<span class="math-container">$\mathbf{r}$</span>) and velocity(<span class="math-container">$\mathbf{v}$</span>) are known</li>
<li>The ellipse lies within the XY-plane</li>
</ol>
<p>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: <span class="math-container">$\mathbf{F2} = \left(f_x,f_y\right)$</span> .</p>
<h2>Using Vectors</h2>
The general equation of an ellipse under these assumptions using vectors is:
<p><span class="math-container">$$ |\mathbf{F2} - \mathbf{p}| + |\mathbf{p}| = 2a  \qquad\mid  z=0$$</span></p>
<p>where:</p>
<ul>
<li><span class="math-container">$a\,\!$</span> is the length of the semi-major axis.</li>
<li><span class="math-container">$\mathbf{F2} = \left(f_x,f_y\right)$</span> is the second (“empty”) focus.</li>
<li><span class="math-container">$\mathbf{p} = \left(x,y\right)$</span> is any (x,y) value satisfying the equation.</li>
</ul>
<p>The semi-major axis length (a) can be calculated as:</p>
<p><span class="math-container">$$a = \frac{\mu |\mathbf{r}|}{2\mu - |\mathbf{r}| \mathbf{v}^2}$$</span></p>
<p>where <span class="math-container">$\mu\ = Gm_1$</span> is the standard gravitational parameter.</p>
<p>The empty focus (<span class="math-container">$\mathbf{F2} = \left(f_x,f_y\right)$</span>) can be found by first determining the Eccentricity vector:</p>
<p><span class="math-container">$$\mathbf{e} = \frac{\mathbf{r}}{|\mathbf{r}|} - \frac{\mathbf{v}\times \mathbf{h}}{\mu}$$</span></p>
<p>Where <span class="math-container">$\mathbf{h}$</span> is the specific angular momentum of the orbiting body:</p>
<p><span class="math-container">$$\mathbf{h} = \mathbf{r} \times \mathbf{v}$$</span></p>
<p>Then</p>
<p><span class="math-container">$$\mathbf{F2} = -2a\mathbf{e}$$</span></p>
<h2>Using XY Coordinates</h2>
This can be done in cartesian coordinates using the following procedure:
<p>The general equation of an ellipse under the assumptions above is:</p>
<p><span class="math-container">$$ \sqrt{ \left(f_x - x\right)^2 + \left(f_y - y\right)^2} + \sqrt{ x^2  + y^2 } = 2a  \qquad\mid  z=0$$</span></p>
<p>Given:</p>
<ul>
<li>the initial position coordinates <span class="math-container">$r_x, r_y \quad$</span></li>
<li>the initial velocity coordinate <span class="math-container">$v_x, v_y \quad$</span></li>
<li>and the gravitational parameter <span class="math-container">$\mu = Gm_1 \quad$</span></li>
</ul>
<p>Then, specific angular momentum:
<span class="math-container">$$h = r_x v_y - r_y v_x \quad$$</span>
initial distance from F1 (at the origin):
<span class="math-container">$$r = \sqrt{r_x^2 + r_y^2} \quad$$</span>
the semi-major axis length:
<span class="math-container">$$a = \frac{\mu r}{2\mu - r \left(v_x^2 + v_y^2 \right)} \quad$$</span>
the Eccentricity vector coordinates:
<span class="math-container">$$e_x = \frac{r_x}{r} - \frac{h v_y}{\mu} \quad$$</span>
<span class="math-container">$$e_y = \frac{r_y}{r} + \frac{h v_x}{\mu} \quad$$</span></p>
<p>Finally, the empty focus coordinates:
<span class="math-container">$$f_x = - 2 a e_x \quad$$</span>
<span class="math-container">$$f_y = - 2 a e_y \quad$$</span></p>
<p>Now the result values <span class="math-container">$f_x$</span>, <span class="math-container">$f_y$</span> and <span class="math-container">$a$</span> can be applied to the general ellipse equation above.</p>
<hr />
<p>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 <em>can</em> 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.</p>

CC BY-SA 4.0
2022-06-03T19:07:13.330Z
Thank you for this! My purposes are just for 2-body systems. So it fits perfectly.
Willyam Carkey
CC BY-SA 4.0
2022-06-03T19:34:35.343Z
Maybe I misunderstood something, but first equation of major axis "a" should be constant during whole orbit. But as my velocity changes also major axis obviously changes too. I am testing it on very small scale, so my G constant is 500. Distance from gravity origin is 18m and starting velocity 40m. According premodeled trajectory eccentricity should be 13m and major axis 19m. But calculated result of major axis is between 0.0001 and 0.001
Willyam Carkey
CC BY-SA 4.0
2022-06-03T21:28:29.377Z
@WillyamCarkey The semi-major axis (a) is calculated from both the current position (**r**) and the current velocity vector (**v**).   As the body in orbit changes its position around the elliptical orbit, it’s velocity *also* changes in such a way that the parameters of the ellipse, including (a) will stay the same, because it is still describing the same ellipse.
RBarryYoung
CC BY-SA 4.0
2022-06-03T22:01:49.653Z
I understand it, yet semi-major axis is changing each frame during movement. But it should not do so. Result is not constant and its number is very small.
Willyam Carkey
CC BY-SA 4.0
2022-06-04T04:24:44.060Z
Then either there’s something wrong with your numbers or with your simulation.  If a is very small then it sounds like you don’t have enough velocity to stay in orbit.
RBarryYoung
CC BY-SA 4.0
2022-06-04T04:29:24.960Z
@WillyamCarkey   If you can post your starting numbers, then we can show how to plug them in and use them.
RBarryYoung
CC BY-SA 4.0
2022-06-04T09:34:08.397Z
@WillyamCarkey if your orbital eccentricity is $13$ (eccentricity is a dimensionless ratio), your spacecraft is on a high-energy hyperbolic trajectory, rather than an elliptical orbit.
notovny
CC BY-SA 4.0
2022-06-09T22:09:00.967Z
Still trying for several days. My actual code is:    for gravity acceleration: Fg = (-G/(dist * dist)) * (loc).normalized(); G is already multiplied by the planet mass.    velocity =  (Fg * deltaTime) + velocity;                        SEMIMAJOR-AXIS:        a = u * r / (2 * u - r * ( v * v ) );     where u is gravitational constant; r is current distance from gravity origin; v is current velocity.  I have tried so many combinations and equations yet still Semi-major axis in not constant. Closer to gravity origin am I, shorter semi-major axis is. But satelite moves correctly as expected.
Willyam Carkey
CC BY-SA 4.0
2022-06-09T22:13:28.280Z
I see now that a = my distance from gravity origin in the current moment. It acts like equation for circular orbit.
Willyam Carkey
CC BY-SA 4.0
2022-06-03T12:15:26.713Z
2022-06-17T16:12:15.440Z
2022-06-17T16:12:15.440Z
RBarryYoung
<p>Thanks to all for help. Now everything is working just fine thanks to RBarryYoung!
For others who struggle with the same problem Im sharing the code (python).
Works only in XZ plain yet:</p>
<pre><code>#Standard gravitational parameter - (Earth)
var u = G*M

#Velocity vector
var Vx = velocity.x
var Vy = velocity.y #is zero
var Vz = velocity.z

#Distance from gravity origin (in this case its Vector3(0,0,0) )
var Rx = global_transform.origin.x
var Ry = global_transform.origin.y #is zero
var Rz = global_transform.origin.z

#specific angular momentum
var h = Rx*Vz - Rz*Vx

#initial distance from gravity origin
var r = sqrt((Rx*Rx) + (Rz*Rz))

#semi-major axis
var a = (u*r)/(2*u - r*(Vx*Vx + Vz*Vz))

#eccentricity
var ex = (Rx/r)-((h*Vz)/u)
var ey = 0
var ez = (Rz/r)+((h*Vx)/u)
var e = Vector3(ex,ey,ez)

#semi-minor axis
var b = (a*sqrt(1-(e.length()*e.length())))/a   #minor axis (0...1)

#empty focus point coordinates
var Fx = -2*a*ex
var Fy = 0
var Fz = -2*a*ez
var F2 = -Vector3(Fx,Fy,Fz)
</code></pre>
<p>After this draw ellipse by integrated function or your own with &quot;a&quot; and &quot;b&quot; as parameters of semi-major and semi-minor axis
After this offset whole ellipse by &quot;e&quot; - eccentricity parameter</p>
<p>Finally rotate ellipse towards F2 vector using <code>-atan2(F2.z,F2.x)</code></p>

CC BY-SA 4.0
2022-06-26T21:18:08.993Z
2022-06-26T21:35:46.810Z
2022-06-26T21:35:46.810Z
Willyam Carkey
<p>I have been struggling for a few days with this.</p>
<p>I know just my distance from gravity origin, gravity source mass and my actual velocity vector on the orbit.
Can I calculate whole trajectory with this? Is it enough to know just these two vectors?</p>
<p>I need to calculate the major and minor axis and eccentricity. It is for small satellites orbiting the Earth.</p>

CC BY-SA 4.0
2022-06-02T21:28:55.840Z
re: *is it enough to know just these 2 vectors* . A way to think about it: Those are the *only* parameters that we have. We have only the present. That's what the "universe knows" right now about the Earth and Sun. it has the current Earth speed vector, the current distance vector and mass. Apparently that's enough for it to "calculate" the trajectory.
d_e
CC BY-SA 4.0
2022-06-03T11:38:33.947Z
The oblateness of the Earth has [a huge influence on most orbits](https://en.wikipedia.org/wiki/Sun-synchronous_orbit#Orbital_precession).
Peter Mortensen
CC BY-SA 4.0
2022-06-03T11:40:21.637Z
Related: *[Homework policy](https://astronomy.meta.stackexchange.com/questions/87/homework-policy)*
Peter Mortensen
CC BY-SA 4.0
2022-06-03T11:43:05.080Z
@d_e: The Earth is not a [point mass](https://en.wikipedia.org/wiki/Point_particle#Point_mass) or spherical.
Peter Mortensen
CC BY-SA 4.0
2022-06-03T11:48:09.953Z
I actually wrote this section of the Wikipedia article because I was so frustrated that I couldn't find it explicitly written out anywhere else: https://en.wikipedia.org/wiki/Elliptic_orbit#From_Initial_Position_and_Velocity
RBarryYoung
CC BY-SA 4.0
2022-06-17T16:33:27.883Z
If your eccentricity is only correct when you're at apoapsis and periapsis, I suspect you're doing a scalar multiplication in a portion of  your eccentricity calculation when you should be taking a cross product.
notovny
CC BY-SA 4.0
2022-06-18T17:21:31.593Z
Mr. Novotny - since Im using only lengths of vectors (float numbers) for my calculations I cant apply that.
Willyam Carkey
CC BY-SA 4.0
2022-06-20T20:17:02.837Z
@WillyamCarkey The angle between the velocity vector and the radial distance vector is _vital_ if you're calculating orbital eccentricity from them (as well as many other calculations on orbits), so I'd probably recommend updating your code so you can apply the cross product.
notovny
<orbit><astrophysics>
How can I calculate an orbital elliptic trajectory from the velocity vector?
Willyam Carkey
# How can I calculate an orbital elliptic trajectory from the velocity vector?

(Asked by: username_0 on 2022-06-02)

I have been struggling for a few days with this.

I know just my distance from gravity origin, gravity source mass and my actual velocity vector on the orbit.
Can I calculate whole trajectory with this? Is it enough to know just these two vectors?

I need to calculate the major and minor axis and eccentricity. It is for small satellites orbiting the Earth.

**Tags:** orbit, astrophysics

> **Comments:**
> **username_1**: re: *is it enough to know just these 2 vectors* . A way to think about it: Those are the *only* parameters that we have. We have only the present. That's what the "universe knows" right now about the Earth and Sun. it has the current Earth speed vector, the current distance vector and mass. Apparently that's enough for it to "calculate" the trajectory.  
> **username_2**: The oblateness of the Earth has [a huge influence on most orbits](https://en.wikipedia.org/wiki/Sun-synchronous_orbit#Orbital_precession).  
> **username_2**: Related: *[Homework policy](https://astronomy.meta.stackexchange.com/questions/87/homework-policy)*  
> **username_2**: @username_1: The Earth is not a [point mass](https://en.wikipedia.org/wiki/Point_particle#Point_mass) or spherical.  
> **username_3**: I actually wrote this section of the Wikipedia article because I was so frustrated that I couldn't find it explicitly written out anywhere else: https://en.wikipedia.org/wiki/Elliptic_orbit#From_Initial_Position_and_Velocity  
> **username_4**: If your eccentricity is only correct when you're at apoapsis and periapsis, I suspect you're doing a scalar multiplication in a portion of  your eccentricity calculation when you should be taking a cross product.  
> **username_0**: Mr. Novotny - since Im using only lengths of vectors (float numbers) for my calculations I cant apply that.  
> **username_4**: @username_0 The angle between the velocity vector and the radial distance vector is _vital_ if you're calculating orbital eccentricity from them (as well as many other calculations on orbits), so I'd probably recommend updating your code so you can apply the cross product.  

---

## 3 answers

### Answer by username_5 on 2022-06-02. Score: 10

Sure, these parameters all fall out of [orbital energy](https://en.wikipedia.org/wiki/Specific_orbital_energy):

$$E=\frac{|\vec{v}|^2}{2}-\frac{\mu}{|\vec{r}|}$$
$$E=-\frac{1}{2}\frac{\mu^2}{|\vec{h}|^2}(1-e^2)$$
$$E=-\frac{\mu}{2a}$$

where $\vec{v}$ is the velocity vector, $\vec{r}$ is the position vector, $\vec{h}=\vec{r} \times \vec{v}$ is the specific relative angular momentum, and $\mu$ is the standard gravitational parameter, $e$ is the eccentricity, and $a$ is the semi-major axis. Calculate $E$ in the first equation, solve and calculate $e$ in the second equation, solve and calculate $a$ in the third equation.

Calculate the [semi-minor axis](https://en.wikipedia.org/wiki/Semi-major_and_semi-minor_axes) $b$ with $b=a\sqrt{1-e^2}$.

> **Comments:**
> **username_6**: Note that if we wish to express ourselves rigorously, we should say: ...where v is the modulus of the velocity vector, r is the modulus of the position vector, $h=\vert r \times v \vert$ is the modulus of the specific angular momentum...  
> **username_5**: @username_6 This answer is just a "back of the napkin", but  I added some vector notation to clarify.  

---

### Answer by username_3 on 2022-06-03. Score: 10

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](https://en.wikipedia.org/wiki/Elliptic_orbit#From_Initial_Position_and_Velocity) 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:

1. 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)
2. The central body’s mass (m1) is known
3. The orbiting body’s initial position($\mathbf{r}$) and velocity($\mathbf{v}$) are known
4. 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.

> **Comments:**
> **username_0**: Thank you for this! My purposes are just for 2-body systems. So it fits perfectly.  
> **username_0**: Maybe I misunderstood something, but first equation of major axis "a" should be constant during whole orbit. But as my velocity changes also major axis obviously changes too. I am testing it on very small scale, so my G constant is 500. Distance from gravity origin is 18m and starting velocity 40m. According premodeled trajectory eccentricity should be 13m and major axis 19m. But calculated result of major axis is between 0.0001 and 0.001  
> **username_3**: @username_0 The semi-major axis (a) is calculated from both the current position (**r**) and the current velocity vector (**v**).   As the body in orbit changes its position around the elliptical orbit, it’s velocity *also* changes in such a way that the parameters of the ellipse, including (a) will stay the same, because it is still describing the same ellipse.  
> **username_0**: I understand it, yet semi-major axis is changing each frame during movement. But it should not do so. Result is not constant and its number is very small.  
> **username_3**: Then either there’s something wrong with your numbers or with your simulation.  If a is very small then it sounds like you don’t have enough velocity to stay in orbit.  
> **username_3**: @username_0   If you can post your starting numbers, then we can show how to plug them in and use them.  
> **username_4**: @username_0 if your orbital eccentricity is $13$ (eccentricity is a dimensionless ratio), your spacecraft is on a high-energy hyperbolic trajectory, rather than an elliptical orbit.  
> **username_0**: Still trying for several days. My actual code is:    for gravity acceleration: Fg = (-G/(dist * dist)) * (loc).normalized(); G is already multiplied by the planet mass.    velocity =  (Fg * deltaTime) + velocity;                        SEMIMAJOR-AXIS:        a = u * r / (2 * u - r * ( v * v ) );     where u is gravitational constant; r is current distance from gravity origin; v is current velocity.  I have tried so many combinations and equations yet still Semi-major axis in not constant. Closer to gravity origin am I, shorter semi-major axis is. But satelite moves correctly as expected.  
> **username_0**: I see now that a = my distance from gravity origin in the current moment. It acts like equation for circular orbit.  

---

### Answer by username_0 on 2022-06-26. Score: 2

Thanks to all for help. Now everything is working just fine thanks to username_3!
For others who struggle with the same problem Im sharing the code (python).
Works only in XZ plain yet:

```
#Standard gravitational parameter - (Earth)
var u = G*M

#Velocity vector
var Vx = velocity.x
var Vy = velocity.y #is zero
var Vz = velocity.z

#Distance from gravity origin (in this case its Vector3(0,0,0) )
var Rx = global_transform.origin.x
var Ry = global_transform.origin.y #is zero
var Rz = global_transform.origin.z

#specific angular momentum
var h = Rx*Vz - Rz*Vx

#initial distance from gravity origin
var r = sqrt((Rx*Rx) + (Rz*Rz))

#semi-major axis
var a = (u*r)/(2*u - r*(Vx*Vx + Vz*Vz))

#eccentricity
var ex = (Rx/r)-((h*Vz)/u)
var ey = 0
var ez = (Rz/r)+((h*Vx)/u)
var e = Vector3(ex,ey,ez)

#semi-minor axis
var b = (a*sqrt(1-(e.length()*e.length())))/a   #minor axis (0...1)

#empty focus point coordinates
var Fx = -2*a*ex
var Fy = 0
var Fz = -2*a*ez
var F2 = -Vector3(Fx,Fy,Fz)

```

After this draw ellipse by integrated function or your own with "a" and "b" as parameters of semi-major and semi-minor axis
After this offset whole ellipse by "e" - eccentricity parameter

Finally rotate ellipse towards F2 vector using `-atan2(F2.z,F2.x)`


---

