Optimising Challenge

BlitzMax Forums/BlitzMax Programming/Optimising Challenge

Tween360 doesn't really do what you want. It interpolates tangents of angles.

This TweenAngle should work, assuming I understand the goal here.
It must be used with non-negative angles less than 360, and t in the range 0 to 1.

Here's an example which also shows how Tween360 is a kind of interpolation, but is not linear.
Print

For f# = 0 To 1 Step 0.125             ' step will be 0.125 * 80 = 10 degrees
	a# = TweenAngle( 100 , 180 , f )
	b# = Tween360( 100 , 180 , f )	
	Print a + "  " + b
Next

' Assumes p1 and p2 are in the range [0,360) and t is in [0,1].
Function TweenAngle#( p1# , p2# , t# )
	
	Local angle# = p1 + t * (p2 - p1)
	
	If p1 <= p2 Then Return angle
	
	angle :+ t * 360.0
	
	If angle < 360.0
		Return angle
	Else
		Return angle - 360.0
	End If
	
End Function

Function Tween360:Float( a:Float , b:Float , time:Float )
	Local ix:Float = Sin(a)
	Local iy:Float = Cos(a)
	Local jx:Float = Sin(b)
	Local jy:Float = Cos(b)
	Return ATan2(ix-(ix-jx)*time,iy-(iy-jy)*time)
End Function