Gravity and orbits


#1

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

My math:


#2

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


#3

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


#4

Ok thanks


#5

Good idea!
Also, no problem!


#6

Ya my math is off by a lot…


#7

Somewhere…


#8

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


#9

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


#10

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


#11

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.


#12

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


#13

@CreationsOfaNoob
I tried it and I got this slingshot affect…


#14

Link to the project:


#15

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.


#16

@Awesome_E, this is the equation I’m using for both x and y
https://discourse-cdn-sjc1.com/gethopscotch/uploads/default/original/3X/d/8/d83dc87af758dfdb0c207bd04fd3d5eeac3edf1c.jpeg
Distance should be distance^2


#17

And what r u solving for?


#18

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.


#19

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