# 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:

4 Likes

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

1 Like

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

7 Likes

Ok thanks

2 Likes

Good idea!
Also, no problem!

2 Likes

Ya my math is off by a lot…

2 Likes

Somewhere…

2 Likes

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

3 Likes

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

2 Likes

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

1 Like

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.

4 Likes

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

1 Like

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

2 Likes

https://c.gethopscotch.com/p/zx2mvzjml

3 Likes

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.

2 Likes

@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.

1 Like

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

2 Likes

@Serenity Sorry if you’re running out of edits. Here’s one to Clive only