Hey fellow gamedevs: how do you lerp between A and B?
=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz
@sstadnicki What are A and B in your case? If they are big lists of reals in memory, i.e. vector-like objects, then the first method is faster.
And also many thanks for introducing me to the word “lerp” (https://en.wiktionary.org/wiki/lerp#Verb). 🙂
=> More informations about this toot | More toots from mrdk@mathstodon.xyz
@sstadnicki No, it is more interesting:
Assume that we want to interpolate between two n-dimensional vectors of reals and the costs of a multiplication and an addition are m and a respectively. Then the cost of the first method is
(2m + a)n + a
and that of the second method is
(m + 2a)n.
This means that on very old hardware on which multiplication is an expensive operation, the second method is better. With modern floating-point processing, we have m = a and the methods are equivalent.
Here I have taken “costs” as something like the required time for the operation. If we take costs as energy consumption, then I think multiplication is still more expensive an the second method is still better.
=> More informations about this toot | More toots from mrdk@mathstodon.xyz
@mrdk @sstadnicki The second method might overflow in cases when neither A nor B overflow (if A is very negative and B very positive).
=> More informations about this toot | More toots from BrKloeckner@piaille.fr
@BrKloeckner I will get back to this. :-)
=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz
@mrdk Largely agreed — with a little caveat that often it's used to interpolate between two lists of items where for one reason or another (1-t) frequently isn't precomputed, so the memoization of that value happens less often than it arguably 'should'.
=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz
@sstadnicki mathematician here, not answering your question but making a tangential point. I would advise to find what really makes sense to be added, expressed as a function f of the value, then use
f^{-1}( t f(A) + (1-t) f(B) )
For example, if your values are side-length of a 2D figure, usually it will feel smoother to have the area be interpolated linearly: you then take f(x)=x^2 and thus interpolate by
√( tA^2 + (1-t)B^2 )
or
√( B^2 + t (A^2 - B^2) )
=> More informations about this toot | More toots from BrKloeckner@piaille.fr
@BrKloeckner Oh, to be sure! This is just for the point where the lerp itself happens; the specific thoughts about these answers that I'm building to are about the mathematical/engineering aspects rather than the design ones.
=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz This content has been proxied by September (3851b).Proxy Information
text/gemini