Shrinking vector

Blitz3D Forums/Blitz3D Programming/Shrinking vector

big10p(Posted 2007) [#1]
I'm using the tried and tested formula to rotate a 2D vector but it's length is decreasing each time it's calculated. Is this due to single precision float innacuracy, or is the formula wrong (got it off the net, somewhere)?
	Graphics 640,480,0,2
	SetBuffer BackBuffer()

	origin_x = 320
	origin_y = 240

	vector_x# = 100
	vector_y# = 0
	
	ang# = 10
	
	While Not KeyHit(1)
		Cls

		; Rotate vector by ang#.
		vector_x = (vector_x * Cos(ang)) - (vector_y * Sin(ang))
		vector_y = (vector_y * Cos(ang)) + (vector_x * Sin(ang))

		Line origin_x, origin_y, origin_x+vector_x, origin_y+vector_y
		Flip True
	Wend

	End



GfK(Posted 2007) [#2]
You're modifying Vector_X then applying that change to Vector_Y. Try this (ensures you're working with values which are constant throughout the 'science bit' ;) :
vx# = vector_x
vy# = vector_y
vector_x = (vx * Cos(ang)) - (vy * Sin(ang))
vector_y = (vy * Cos(ang)) + (vx * Sin(ang))



big10p(Posted 2007) [#3]
lol - it just occured to me what I was doing wrong. I'm such a plonker. Has been one of those days! :P

Thanks.