lib/driving_physics/disk.rb in driving_physics-0.0.1.1 vs lib/driving_physics/disk.rb in driving_physics-0.0.1.2

- old
+ new

@@ -128,12 +128,13 @@ def normal_force @normal_force ||= self.mass * @env.g @normal_force end - def alpha(torque) - torque / self.rotational_inertia + def alpha(torque, omega: 0, normal_force: nil) + (torque - self.rotating_friction(omega, normal_force: normal_force)) / + self.rotational_inertia end def implied_torque(alpha) alpha * self.rotational_inertia end @@ -173,12 +174,12 @@ # modeled as a tiny but increasing torque opposing omega # also scales with normal force # maybe not physically faithful but close enough def rotating_friction(omega, normal_force: nil) return omega if omega.zero? + normal_force = self.normal_force if normal_force.nil? mag = omega.abs sign = omega / mag - -1 * sign * (normal_force || self.normal_force) * - (@base_friction + @omega_friction * mag) + -1 * sign * normal_force * (@base_friction + mag * @omega_friction) end end end