Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

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.

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

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 wink.png

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!