Curve-value function

BlitzPlus Forums/BlitzPlus Programming/Curve-value function

WillKoh(Posted 2005) [#1]
I'd like to have a function that returns the y value at a certain x in a curve that's shaped like a half circle. This hypoth half circ could be sized as the one you'd see by this code (left "leg" is X=0):

For ang# = -90 To 90
 x# = x# + Cos(ang) * 1
 Y# = y# + Sin(ang) * 1
 plot 100+x, 100+y
next


and another were its shaped like a quad of a circle that's not "standing on it's left leg" as would be the case if chg 90 to 0 above, but instead lying down:

        o   o   o         Y at x =??
    o                o
o                       o
X->


I'm thinking something without actually having to draw it and Point(x,y) my way up to find the roof.


sswift(Posted 2005) [#2]
; -------------------------------------------------------------------------------------------------------------------
; 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#)