Sign in to follow this  

mapping a variable

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings everyone. I'm trying to linearly map a variable from one coordinate range to another. What is the equation for this? E.g. I will get a variable in [0,900] and I want to map it to [-750, 750]. If you know of a link where this is described, no problem.

Share this post


Link to post
Share on other sites
Let's say your ranges are: [a,b]:[0,900] and [i,j]:[-750,750].
And the value you want to map is x: a<=x<=b

Do a reverse lerp (ie, linear interpolation), then forward.

Lerp says: x = a + f(b - a)
Solve that for f.

f = (x - a) / (b - a)

Now use f to lerp the other range.
y = i + f(j - i)

Fill in value for f:
y = i + ( (x-a)(j-i) / (b-a) )

Share this post


Link to post
Share on other sites
Since [0,900] and [-750,750] are different in size there will be an issue of decimation and you can't go from one to the other then back without possible loss of information.

[0,900] is 900 units.
[-750,750] is 1500 units.

Assuming origin of each system at 0 and -750 respectively.

Let A be a point in [0,900]. You need to get the unit vector for A call it A'.

A' = A / 900 (900 is units in system a)

Then you need to rescale to b.

B1 = A' * 1500;

And shift in b to the origin:

B = B1 - 750;


So in a simple formula:

FB(a) = a / 900 * 1500 - 750;


There you go. :)

Share this post


Link to post
Share on other sites

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this