DeaD_EyE

norm input, scale output

Oct 3rd, 2020
1,097
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from functools import partial
  2.  
  3.  
  4. def scale(min_v, max_v, min_unit, max_unit, voltage):
  5.     v_range = max_v - min_v
  6.     u_range = max_unit - min_unit
  7.     norm = (voltage - min_v) / v_range
  8.     return norm * u_range + min_unit
  9.  
  10. minimum_voltage = 0
  11. maximum_voltage = 10
  12. minimum_distance = 10 # cm
  13. maximum_distance = 100 # cm
  14.  
  15. distance1 = partial(scale, minimum_voltage, maximum_voltage, minimum_distance, maximum_distance)
  16. print(distance1(5))
  17.  
RAW Paste Data