Math - Convert Arbitrary Length to Range From -1.0 to 1.0?

Posted by TheDarkIn1978 on Stack Overflow See other posts from Stack Overflow or by TheDarkIn1978
Published on 2010-06-18T03:23:26Z Indexed on 2010/06/18 3:33 UTC
Read the original article Hit count: 158

Filed under:
|
|
|

how can i convert a length into a range of -1.0 to 1.0?

example: my stage is 440px in length and accepts mouse events. i would like to click in the middle of the stage, and rather than an output of X = 220, i'd like it to be X = 0. similarly, i'd like the real X = 0 to become X = -1.0 and the real X = 440 to become X = 1.0.

i don't have access to the stage, so i can't simply center-register it, which would make this process a lot easier. also, it's not possible to dynamically change the actual size of my stage, so i'm looking for a formula that will translate the mouse's real X coordinate of the stage to evenly fit within a range from -1 to 1.

© Stack Overflow or respective owner

Related posts about math

Related posts about convert