Module: DrivingPhysics::VectorForce

Defined in:
lib/driving_physics/vector_force.rb

Class Method Summary collapse

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



106
107
108
109
110
111
112
113
# File 'lib/driving_physics/vector_force.rb', line 106

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



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/driving_physics/vector_force.rb', line 156

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



124
125
126
127
128
129
# File 'lib/driving_physics/vector_force.rb', line 124

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



134
135
136
137
138
# File 'lib/driving_physics/vector_force.rb', line 134

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



116
117
118
119
120
121
# File 'lib/driving_physics/vector_force.rb', line 116

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



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/driving_physics/vector_force.rb', line 144

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