rotating a vector?

BlitzMax Forums/BlitzMax Programming/rotating a vector?

Actually, I was mistaken. The sin function I made, while less accurate, is actually slightly faster than the built in function. But only slightly. Like 17ms instead of 20.

T1 = MilliSecs()

For A# = -90 To 90
	
	R# = Sin(A#) - Sin2(A#)
	Print R#

Next
	
T2 = MilliSecs()	

'For A# = 0 To 90

'	R# = Sin2(A#)
'	Print R#
				
'Next

T3 = MilliSecs()

Print T2-T1
Print T3-T2

WaitKey()


Function Sin2#(A#)

	Local R# = A# * Pi/180.0

	'Return R# - R#^3.0/6 + R#^5.0/120 - R#^7.0/5040 + R#^9.0/362880 + R#^11.0/39916800 ' 310ms
	Return R# - R#*R#*R#/6 + R#*R#*R#*R#*R#/120 - R#*R#*R#*R#*R#*R#*R#/5040 ' 17ms

End Function


It's most accurate from -90 to +90. It's less accurate from -180 to 180, but because the values are mirrored within those extended ranges, with a little clever coding you could get the same accuracy in those sections. But then you'd lose the speed increase. You can make it even faster and less accurate by like, removing "- R#*R#*R#*R#*R#*R#*R#/5040" from the calculation. That's an neverneding series. R^3/3! + R^5/5! -R^7/7! where 7! means (7*6*5*4*3*2*1). So if you extend that series you can make it more accurate.

I tried to reduce the number of times I multiply R by itself by storing it in a variable but that cost me a little speed rather than gaining anything.