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



83
84
85
86
87
88
89
# 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)
  -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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/driving_physics/vector_force.rb', line 120

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

.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



98
99
100
101
102
# File 'lib/driving_physics/vector_force.rb', line 98

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_cof: ROT_COF) ⇒ Object



91
92
93
# File 'lib/driving_physics/vector_force.rb', line 91

def self.rotational_resistance(velocity, rot_cof: ROT_COF)
  -1 * velocity * rot_cof
end

.velocity_resistance(velocity, frontal_area: FRONTAL_AREA, drag_cof: DRAG_COF, air_density: AIR_DENSITY, rot_cof: ROT_COF) ⇒ Object

convenience methods



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/driving_physics/vector_force.rb', line 108

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