Curve-value function

BlitzPlus Forums/BlitzPlus Programming/Curve-value function

; -------------------------------------------------------------------------------------------------------------------
; This function allows you to do the reverse of a linear interpolation between two values.
;
; Instead of specifying the tween value, you specify the value which you want the know the tween of.
;
; Essentially, this function will tell you where a value is between two other values.  If the value is between
; the two values, then the result will be in the range of 0..1.
; -------------------------------------------------------------------------------------------------------------------
Function InverseTween#(X1#, X2#, X#)
	
	; If the difference between x1 and x2 is 0, then there is no tween value which will give you the value of
	; x, unless x is equal to x1 or x2, in which case all tween values will give you the correct result.
	; So we just return 0 for the tweening value if the difference is 0.

	If (X2# - X1#) <> 0
		Return (X# - X1#) / (X2# - X1#)
	Else
		Return 0
	EndIf
	
End Function



X1 is the start X of your curve. 
X2 is the end X of your curve.
X is the X location you want to know the Y value of.
Amplitude is the maximum height of the Y curve.

Tween# = InverseTween#(X1#, X2#, X#)
Y# = Amplitude# * Sin(180.0*Tween#)