Sha256: ef231e1ffceb8a6a5e4963b1d13739fe68f4f0cb7c76eb8fc8a619183b70e3aa

Contents?: true

Size: 586 Bytes

Versions: 1

Compression:

Stored size: 586 Bytes

Contents

require 'driving_physics/scalar_force'

DP = DrivingPhysics

pos = 0               # m
spd = 0               # m/s
mass = 1000           # kg
weight = mass * DP::G # N
drive_force = 7000    # N
duration = 100        # seconds
tick = 1.0 / DP::HZ

(duration * DP::HZ).times { |i|
  nf = drive_force - DP::ScalarForce.all_resistance(spd, nf_mag: weight)

  a = DP.acc(nf, mass)
  spd = DP.vel(spd, a, dt: tick)
  pos = DP.pos(pos, spd, dt: tick)

  if i % DP::HZ == 0
    puts [i / DP::HZ,
          format("%.2f m/s", spd),
          format("%.2f m", pos),
         ].join("\t")
  end
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
driving_physics-0.0.1.1 demo/scalar_force.rb