View Single Post
  #5   Spotlight this post!  
Unread 17-02-2015, 20:21
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Axis/Slider Scale

Quote:
Originally Posted by Jared View Post
Code:
(stick.get() + 1) / 2
Quote:
Originally Posted by Ether View Post





Jared gave you the answer.

If you are interested, here's the algebra to solve that kind of problem, for any input and output range, assuming you want a linear conversion from input to output:

Let x be the input and y be the output.

You want a linear conversion, so use the equation for a line:

y = mx + b

When x is -1 you want y to be 0:

0 = m(-1) + b ....(Equation1)

When x is 1 you want y to be 1:

1 = m(1) + b .....(Equation2)

You have 2 equations with two unknowns, so solve them.

Add the two equations:

1 = 2b .....=>..... b = (1/2)

Subtract Equation1 from Equation2:

1 = 2m .....=>..... m=(1/2)

So the conversion is y = (1/2)x + (1/2) = (x+1)/2


Thanks for that information and thanks for the great explanation, Ether. I hadn't thought of it that way (as a linear equation pair) but that actually makes sense.

Thank you!