Actually, the code you have for Fast_Sin and Fast_Cos runs more slowly than the intrinsic sin and cos functions. This is mainly because of the Mod statement.
If you can insure that the angle never goes beyond +-359 then you can remove that statement. Here is a modified version that runs slightly faster than the intrinsic functions and faster than your original function with more accuracy.
These formulas were derived from the following trig formulas
cos(A+a) = Cos(A)*Cos(a) - Sin(A)*Sin(a)
sin(A+a)= Sin(A)*Cos(a) + Cos(A)*Sin(a)
Sin(a) = a - (a^3)/6 + (a^5)/720 - ... where a is in radians
Cos(a) = 1 - (a^2)/2 + (a^4)/24 - ... where a is in radiansVB Code:
Public Function Fast_Cos(ByVal Theta As Single) As Single If Theta < 0 Then Theta = Theta + 360 Dim Theta_Integer As Long Dim Theta_Fraction As Single 'remove this checking, too slow ' Theta_Integer = Theta Mod 360 Theta_Integer = CLng(Theta) Theta_Fraction = Theta - Theta_Integer 'Old function 'Fast_Cos = Cos_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Cos_Look_Up_Table(Theta_Integer + 1) - Cos_Look_Up_Table(Theta_Integer)) 'New function 'cos(A+a) = Cos(A)*Cos(a) - Sin(A)*Sin(a) Fast_Cos = Cos_Look_Up_Table(Theta_Integer) - Sin_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad End Function Public Function Fast_Sin(ByVal Theta As Single) As Single If Theta < 0 Then Theta = Theta + 360 Dim Theta_Integer As Long Dim Theta_Fraction As Single 'remove this checking, too slow 'Theta_Integer = Theta Mod 360 Theta_Integer = CLng(Theta) Theta_Fraction = Theta - Theta_Integer 'old function 'Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Theta_Fraction * (Sin_Look_Up_Table(Theta_Integer + 1) - Sin_Look_Up_Table(Theta_Integer)) 'New function 'sin(A+a)= Sin(A)*Cos(a) + Cos(A)*Sin(a) Fast_Sin = Sin_Look_Up_Table(Theta_Integer) + Cos_Look_Up_Table(Theta_Integer) * Theta_Fraction * DegToRad End Function




Reply With Quote