1

I am trying to make a orbit simulator in Python and i have some basic mechanics like acceleration , velocity implemented.
I was trying to implement Newtonian gravitational formula GMm/r**2
But there to calculate the direction of the force im doing something like this
dir = Vec2(object.posX-object2.posX,object.posY-object2.posY)
and then applying the math.atan function to convert the slope into angle
dir_angle = math.atan(dir.y/dir.x)
This is later used to calculate the X and Y direction component of force as acceleration

object2.acceleration_x = dt * f * math.sin(dir_angle)/object2.mass
object2.acceleration_y = dt * f * math.cos(dir_angle)/object2.mass

But value of dir.x and dir.y initially is -100,100
so atan is -.78 but eventually , the dirx and diry become 1,-1.
But the slope remains the same and the angle remains the same , not reversing the direction of force.
How can i fix this so the force can change direction when I want.

0 Answers0