quick math question

BlitzMax Forums/BlitzMax Programming/quick math question

dmaz(Posted 2007) [#1]
I don't feel like thinking right now...

anybody got a nice small algorithm that moves from one point to another with an exponential interpolation to a stop?


sswift(Posted 2007) [#2]
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function allows you to do an exponential interpolation between two values.
	' 
	' Pow# = A power of 1.0 will produce a linear tween.
	'        A power of 2.0 will cause the value to change slowly at first, then change quickly at the end.
	'		 A power of 0.5 will do the opposite, causing the value to change quickly at first then slow down.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Function TweenExponential#(X1#, X2#, Tween#, Pow#=2.0)
								
			Tween# = Tween#^Pow#
			Return X1# + (Tween# * (X2# - X1#))
		
		End Function



To use this pass the start and end position as X1 and X2, and call the function repeatedly, adjusting tween from 0..1 over linear time. The function outputs the position adjusted according to the specified exponent.

So with an exponent of 1, a tween of 0.5 would return the point in the midle of X1 and X2. But with an exponent of 2, a tween of 0.5 would return something quite a bit closer to X1 than X2, because that causes the point to move slower at the start.

You'll need to call the function twice each frame, once for the X axis, and once for the Y.


SoggyP(Posted 2007) [#3]
Hello.

Whut?

Goodbye.


dmaz(Posted 2007) [#4]
thanks sswift! exactly what I was looking for.