Gravity and orbits


I have an orbit sim but my math is off by a bit… idk where or why so I need help.

My math:


Here, I will tag @Rodrigo and @hopscotch-curators


Imma going to tag @pomtl just too see if anyone can help…


Ok thanks


Good idea!
Also, no problem!


Ya my math is off by a lot…




Wow I can’t do math that good!!!


Can you type the original equation / expression? There are a few letters I can’t read out. (You can use x^2 for x squared) btw you can also tag @CodeHelp


Ok ya I’ll find the original equation just give me a bit


To calculate gravitational force, you can use this formula:

To simplify this, you can break it into X and Y velocity (you could also replace ”𝒎1𝒎2” with another value)

(should say distance2)
And the same for Y.

That’s basically all you need.


Thanks! I’ll try that @CreationsOfaNoob, that will help a lot.


I tried it and I got this slingshot affect…


Link to the project:


I have no idea how to help, really. But I am pretty sure COAN knows this kind of stuff, and if he can’t help you for some reason, try to ask @ThinBuffalo.


@Awesome_E, this is the equation I’m using for both x and y
Distance should be distance^2


And what r u solving for?


The code is actually working, but there are a couple of things you may want to change.
First of all, you could cut down a lot on the amount of variables.

  • Where you calculate the ”radius”, you could change it to √((self x - sun x)2 + (self y - sun y)2) instead of doing the subtraction separately.
  • Remove -x and -y. They aren’t used anywhere.

Second, you should give the planet an initial velocity, otherwise it will shoot straight for the sun with that slingshot effect.


Ohh ok that makes sense I’ll fix that thank you @CreationsOfaNoob