Module: DrivingPhysics::VectorForce
- Defined in:
- lib/driving_physics/vector_force.rb
Class Method Summary collapse
-
.air_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY) ⇒ Object
velocity is a vector; return value is a force vector.
- .all_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF, dir:, nf_mag:, roll_cof: ROLL_COF) ⇒ Object
-
.omega_resistance(omega, rot_const: ROT_TQ_CONST, rot_cof: ROT_TQ_COF) ⇒ Object
return a torque opposing omega, representing friction / hysteresis.
-
.rolling_resistance(nf_mag, dir:, roll_cof: ROLL_COF) ⇒ Object
dir is drive_force vector or velocity vector; will be normalized normal_force is a magnitude, not a vector.
-
.rotational_resistance(velocity, rot_const: ROT_CONST, rot_cof: ROT_COF) ⇒ Object
return a force opposing velocity, representing friction / hysteresis.
-
.velocity_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF) ⇒ Object
convenience methods.
Class Method Details
.air_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY) ⇒ Object
velocity is a vector; return value is a force vector
83 84 85 86 87 88 89 90 |
# File 'lib/driving_physics/vector_force.rb', line 83 def self.air_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY) return velocity if velocity.zero? -1 * 0.5 * frontal_area * drag_cof * air_density * velocity * velocity.magnitude end |
.all_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF, dir:, nf_mag:, roll_cof: ROLL_COF) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/driving_physics/vector_force.rb', line 133 def self.all_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF, dir:, nf_mag:, roll_cof: ROLL_COF) velocity_resistance(velocity, frontal_area: frontal_area, drag_cof: drag_cof, air_density: air_density, rot_cof: rot_cof) + rolling_resistance(nf_mag, dir: dir, roll_cof: roll_cof) end |
.omega_resistance(omega, rot_const: ROT_TQ_CONST, rot_cof: ROT_TQ_COF) ⇒ Object
return a torque opposing omega, representing friction / hysteresis
101 102 103 104 105 106 |
# File 'lib/driving_physics/vector_force.rb', line 101 def self.omega_resistance(omega, rot_const: ROT_TQ_CONST, rot_cof: ROT_TQ_COF) return 0 if omega == 0.0 omega * ROT_TQ_COF + ROT_TQ_CONST end |
.rolling_resistance(nf_mag, dir:, roll_cof: ROLL_COF) ⇒ Object
dir is drive_force vector or velocity vector; will be normalized normal_force is a magnitude, not a vector
111 112 113 114 115 |
# File 'lib/driving_physics/vector_force.rb', line 111 def self.rolling_resistance(nf_mag, dir:, roll_cof: ROLL_COF) return dir if dir.zero? # don't try to normalize a zero vector nf_mag = nf_mag.magnitude if nf_mag.is_a? Vector -1 * dir.normalize * roll_cof * nf_mag end |
.rotational_resistance(velocity, rot_const: ROT_CONST, rot_cof: ROT_COF) ⇒ Object
return a force opposing velocity, representing friction / hysteresis
93 94 95 96 97 98 |
# File 'lib/driving_physics/vector_force.rb', line 93 def self.rotational_resistance(velocity, rot_const: ROT_CONST, rot_cof: ROT_COF) return velocity if velocity.zero? -1 * velocity * rot_cof + -1 * velocity.normalize * rot_const end |
.velocity_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF) ⇒ Object
convenience methods
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/driving_physics/vector_force.rb', line 121 def self.velocity_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF) air_resistance(velocity, frontal_area: frontal_area, drag_cof: drag_cof, air_density: air_density) + rotational_resistance(velocity, rot_cof: rot_cof) end |