Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
You want to scale from one linear range to another. That can always be done with y = mx + b where X is the input value and Y the output value. M is the scale factor, and B the offset. You ...
Answer
#1: Initial revision
You want to scale from one linear range to another. That can always be done with y = mx + b where X is the input value and Y the output value. M is the scale factor, and B the offset. You want to map (-1 .. 1) to (0 .. 319). The scale factor therefore has to be 319/2 = 159.5 = m. Now that you know M, pick any known X and Y pair and solve for B: b = y - mx You know that -1 maps to 0, so y - mx = 0 - (159.5)(-1) = 159.5 = b The final result is therefore y = 159.5x + 159.5 Note that this method works for mapping any linear range to any other linear range.