# Help with the math on this?

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

## Recommended Posts

I am not sure what this is even called in math terms, but here I go...

i have a range from 0 to 1

and I want to take the value of 1 and make that 0, and 0 and make that 1. and if I have .1 make it .9 and .9 make it .1

So I am not sure how to do this. And/or what it's called.

Thanks!

##### Share on other sites

It's called linear interpolation (Lerp).

Thanks

##### Share on other sites

The 2 points are p0 = 1 and p1 = 0 (values at time t = 0 and t = 1 respectively).

He mentioned specific values for t in his post (t = 0.1 and 0.9).

Lerp is the general case for this

p = (1 - t) * p0 + t * p1 = p0 - t * (p0 - p1)

Plugging in p0 = 1 and p1 = 0 we get

p = 1 - t(1 - 0) = 1 - t

which is what fir said too (with variables named differently, y == p and x == t)

##### Share on other sites

From reading his post, he wants 0 --> 1, 1 --> 0   and  0.1 --> 0.9 and 0.9 --> 0.1.

Indeed, y = 1.0 - x

You can use it to determine diagonals on slopes if you have square tiles, for example.

Edited by Kaptein

##### Share on other sites

I'd read his post again then ;)

He wants

0.0 -> 1.0

0.1 -> 0.9

0.9 -> 0.1

1.0 -> 0.0

##### Share on other sites

I agree with Diego that it's.. kind of a stretch to call this linear interpolation. It's just a simple complement, and just happens to be a special case of linear interpolation with a = 1, b = 0 (and probably a special case of plenty of other transforms). But anyway it's good to have a reference to it since most likely MARS_999 will need it soon

##### Share on other sites

Why stop at linear interpolation? We can complicate things further and think of it as polynomial interpolation: There is a unique polynomial of degree up to 3 such that f(0)=1, f(0.1)=0.9, f(0.9)=0.1 and f(1)=0.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631781
• Total Posts
3002314
×