Ancestors

Toot

Written by Steven Stadnicki (he/him) on 2024-08-08 at 19:59

Hey fellow gamedevs: how do you lerp between A and B?

=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz

Descendants

Written by Markus Redeker on 2024-08-09 at 08:08

@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

Written by Markus Redeker on 2024-08-09 at 08:34

@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

Written by Benoît Régent-Kloeckner on 2024-08-09 at 10:09

@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

Written by Steven Stadnicki (he/him) on 2024-08-09 at 16:33

@BrKloeckner I will get back to this. :-)

=> More informations about this toot | More toots from sstadnicki@mathstodon.xyz

Written by Steven Stadnicki (he/him) on 2024-08-09 at 16:32

@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

Written by Benoît Régent-Kloeckner on 2024-08-09 at 10:00

@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

Written by Steven Stadnicki (he/him) on 2024-08-09 at 16:36

@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

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/112928171392896250
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
369.856963 milliseconds
Gemini-to-HTML Time
1.241017 milliseconds

This content has been proxied by September (3851b).