Law of gravitation

pull/1/head
E. Almqvist 3 years ago
parent ede0ee7f5e
commit c07e1374e8
  1. 2
      app.rb
  2. 3
      physobj.rb

@ -45,7 +45,7 @@ planet = Planet.new("Earth", window, 0xff_aaffaa)
planet.pos = Vector[800, 450]
cube = PhysCube.new("Cube", window, 8, 8)
cube.vel = Vector[10, 0]
cube.vel = Vector[1, 0]
planet.orbit([cube])
window.planets << planet

@ -1,5 +1,6 @@
require "matrix"
GRAV_CONSTANT = 1e+2
class PhysObj
attr_accessor :world, :pos, :vel, :accel, :x, :y
@ -91,7 +92,7 @@ class Planet < PhysCube
private def calculate_gravity_vector(obj)
dir_vec = self.pos - obj.pos
return (self.gravity * dir_vec)/dir_vec.magnitude
return (GRAV_CONSTANT * self.gravity * dir_vec)/(dir_vec.magnitude**2)
end
def orbit(physobjs)

Loading…
Cancel
Save