lib/driving_physics/disk.rb in driving_physics-0.0.2.1 vs lib/driving_physics/disk.rb in driving_physics-0.0.3.1

- old
+ new

@@ -78,35 +78,10 @@ # convert acc/vel/pos to alpha/omega/theta def self.rotational(tangential, radius) tangential.to_f / radius end - # vectors only - def self.torque_vector(force, radius) - if !force.is_a?(Vector) or force.size != 2 - raise(ArgumentError, "force must be a 2D vector") - end - if !radius.is_a?(Vector) or radius.size != 2 - raise(ArgumentError, "radius must be a 2D vector") - end - force = Vector[force[0], force[1], 0] - radius = Vector[radius[0], radius[1], 0] - force.cross(radius) - end - - # vectors only - def self.force_vector(torque, radius) - if !torque.is_a?(Vector) or torque.size != 3 - raise(ArgumentError, "torque must be a 3D vector") - end - if !radius.is_a?(Vector) or radius.size != 2 - raise(ArgumentError, "radius must be a 2D vector") - end - radius = Vector[radius[0], radius[1], 0] - radius.cross(torque) / radius.dot(radius) - end - attr_reader :env attr_accessor :radius, :width, :density, :base_friction, :omega_friction def initialize(env) @env = env @@ -126,9 +101,14 @@ end def normal_force @normal_force ||= self.mass * @env.g @normal_force + end + + # E = (1/2) (I) (omega^2) + def energy(omega) + 0.5 * self.rotational_inertia * omega ** 2 end def alpha(torque, omega: 0, normal_force: nil) (torque - self.rotating_friction(omega, normal_force: normal_force)) / self.rotational_inertia