Help with the math on this?

Started by
23 comments, last by Ectara 9 years, 9 months ago

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!

Advertisement

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!

it would be y= 1.0 - x

It's called linear interpolation (Lerp).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Thanks

It's called linear interpolation (Lerp).

Really? It sounds like just a complement like fir said. Linear interpolation requires 2 points (may be farther than 1 unit from the origin) and a delta between 0 and 1, and the original post doesn't name any of that.

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)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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.

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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 wink.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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.

This topic is closed to new replies.

Advertisement