Answer the question
In order to leave comments, you need to log in
How to convert a number from one range to another?
Hello.
Interested in the following question, how to convert a number from one range (low; hight) to another (low_2; hight_2)?
From a specific task, I need to somehow take numbers from the range -3; 3 and convert them to the range 0; 100.
How to do it?)
Answer the question
In order to leave comments, you need to log in
# Положение числа в исходном отрезке, от 0 до 1
relative_value = (value - low) / (high - low)
# Накладываем его на конечный отрезок
scaled_value = low_2 + (high_2 - low_2) * relative_value
ProMaks, I just want to say the same thing that Anatoly Scherbakov already wrote about, but in other words.
Linear interpolation using the equation of a straight line will help here. Look, for example, at The equation of a straight line passing through two different points on a plane en.onlinemschool.com/math/library/analytic_geometr...
In that equation, x1=-3, x2=3, y1=0, y2=100.
As soon as you substitute these values into the equation of a straight line and express y (scaled_value), you will immediately get the expression that Anatoly Scherbakov uses.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question