Rotating Vectors
BlitzMax Forums/BlitzMax Programming/Rotating Vectors That's how I'd do it too. I'm going out on a limb here and saying there isn't a beter way...(now watch people disprove me ;-))
I use:
cos_rot# = Cos(ang#)
sin_rot# = Sin(ang#)
new_x# = (x * cos_rot) - (y * sin_rot)
new_y# = (y * cos_rot) + (x * sin_rot)
;)
That rotates the existing vector by ang, though. It doesn't create a vector with an absolute angle of ang.
cos_rot# = Cos(ang#)
sin_rot# = Sin(ang#)
new_x# = (x * cos_rot) - (y * sin_rot)
new_y# = (y * cos_rot) + (x * sin_rot)
;)
That rotates the existing vector by ang, though. It doesn't create a vector with an absolute angle of ang.
Ah yes a good ole Matrix. In fact I lied as my TVector type has this method:
But I like the way Big10p is storing the cos and sin before the main calc to reduce the number of calls to cos and sin. Wonder if it's faster creating those two extra local variables. I guess a test is in order.
Method Rotate(angle!) 'clockwise Local tx# = (x * Cos(angle)) - (y * Sin(angle)) Local ty# = (x * Sin(angle)) + (y * Cos(angle)) x=tx y=ty End Method
But I like the way Big10p is storing the cos and sin before the main calc to reduce the number of calls to cos and sin. Wonder if it's faster creating those two extra local variables. I guess a test is in order.
Wonder if it's faster creating those two extra local variables. I guess a test is in order.
I've never tested, either. Old habits die hard, is all. :) That uses the exact same method. :)
Indeed it does.
I actually posted after GA's first response.
I actually posted after GA's first response.
Ah.