Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by SarperS · Sep 11, 2015 at 01:13 PM · mathinterpolationexponential

Logarithmic Interpolation

I am trying to come up with a method which does logarithmic and exponential interpolation.

We know that linear interpolation Mathf.Lerp as below uses from + t . (to-from)

 float Lerp(float from, float to, float t);


And ideal method I need would look like "Logerp(from, to, t, w)"

  • A start value (from)

  • An end value (to)

  • A 0-1 range percentage to use for interpolation (t)

  • And finally as an addition to the classical lerp parameters above, a 0-1 range parameter that defines the distribution weight of the values. So if it's closer to 0, distribution will be logarithmic. If it's closer to 1, it will be exponential. If it's exactly 0.5, distribution will be linear. So basically it defines the curvature of the logarithmic graph. (w)

Can you write such a method or a mathematical representation of the described requirement?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SarperS · Sep 11, 2015 at 01:22 PM 0
Share

@troien You were very helpful with a math problem I've posted before, maybe give this one a shot too?

avatar image _Gkxd · Sep 11, 2015 at 02:15 PM 1
Share

This paper explains the concept quite nicely: http://www.cmu.edu/biolphys/deserno/pdf/log_interpol.pdf

avatar image SarperS _Gkxd · Sep 11, 2015 at 04:15 PM 0
Share

Nice document, thanks. I see that to^t.from^1-t should give me the logarithmic interpolation value. But I'm having two problems

I can't find a way to modify the steepness of the graph And also how to make it exponential too

avatar image _Gkxd SarperS · Sep 11, 2015 at 06:07 PM 1
Share

I think what you are looking for isn't a logarithmic or exponential interpolation. Rather, you want something of the form

 FInterpolation(a, b, t) = (1 - F(t))*a + F(t)*b

where F(t) is any function that maps the range [0,1] to [0,1].

In the case of linear interpolation (lerp), F(t) = t. What you could do ins$$anonymous$$d is have F(t) = t^w (where ^ denotes exponent), for some w > 0. This wouldn't be logarithmic or exponential, but it seems to be what you're looking for.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SarperS · Sep 12, 2015 at 03:57 PM

I ended up using an AnimationCurve. I have a public field of type AnimationCurve with two keyframes at 0 and 1, which I can edit from the inspector too. When I want to get a specific value at a time I just use the below code.

 return from + curve.Evaluate(t) * (to - from);

If I wasn't going to go with the AnimationCurve, I was going to use below two formulas for exponential and logarithmic curves respectively

 from + (to - from) * Mathf.Pow(t, w);
 to - (to - from) * Mathf.Log(t, w);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image _Gkxd · Sep 12, 2015 at 06:30 PM 0
Share

The problem with using logarithm in this way is that it maps the range [0,1] to [-infinity,0], not [0,1], so the second formula is actually problematic. If you use t = 0 in the formula, the logarithm would return -infinity, which would almost certainly break things.

The first formula that you have is actually a power function ins$$anonymous$$d of an exponential function. In an exponential, the exponent changes and the base is fixed, so you would want $$anonymous$$athf.Pow(w,t) ins$$anonymous$$d. But still, this maps the range [0,1] to [1,w], which would also probably break things.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Meaning of inWeight and outWeight in Keyframe, or recalculate tangents from sampling 0 Answers

What exactly does Mathf.InverseLerp() do? 4 Answers

Elastic Interpolation of Quaternion 0 Answers

how to calculate the angle between two vectors? 6 Answers

How to Instantiate from mouse pos? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges