I've used a combination of code (c and phaelax's vector routines) to try to convert an angle in degrees to a vector and have come up with the attached code. Unfortunately no matter what angle i feed it i always get x=1, y=0
Any help would be greatly appreciated
#constant PI=3.141592653589793
type vector2D
x as float
y as float
endtype
/****************************************************************
Converts an angle to a 2D vector
****************************************************************/
function AngleToVector2D(angle as float)
radians as float
vector as vector2D
radians = angle * (PI / 180)
vector.x = Cos(radians)
vector.y = Sin(radians)
vector = normalizeVector2D(vector)
endfunction vector
/****************************************************************
Returns a normalized 2D vector (or unit vector) of v1
****************************************************************/
function normalizeVector2D(v1 as Vector2D)
d as float
v as Vector2D
d = getVector2DLength(v1)
v.x = v1.x / d
v.y = v1.y / d
endfunction v
/****************************************************************
Returns the length (or magnitude) of a 2D vector
****************************************************************/
function getVector2DLength(v1 as Vector2D)
l as float
l = v1.x*v1.x + v1.y*v1.y
l = sqrt(l)
endfunction l
Sign up for NaGaCreMo!