You may think this is being pedantic but in order to answer your question properly, it is important that we are all using the correct terminology.
Velocity is a vector.
Speed is a scaler.
They are very different things! Velocity has both speed and direction. Velocity is very different to speed although in many cases people seem to use the terms interchangeably - They are wrong!
When you say you have the velocity x and Y components do you realy mean you have the position that it is to be applied? Because if you actually have the velocity as a vector then you don\'t need any maths at all.
However, either way, here are some functions that should help:
////////////////////////
// VELOCITY
function getVelocityFromSpeedAndAngle( speed as float, angle as float )
v as tVect2
v.x = cos(angle) * speed
v.y = sin(angle) * speed
endfunction v
function getVelocityFromUnitVector( speed as float, v as tVect2 )
v = multiplyVector2( v, speed )
endfunction v
////////////////////////
// MULTIPLY VECTORS
function multiplyVector2( v1 as tVect2, n as float )
local t as tVect2
t.x = v1.x * n
t.y = v1.y * n
endfunction t
type tVect2
x as float
y as float
endtype
@easter bunny Your code calculates a directional vector and multiplies it by speed twice(!)
[EDIT]
This function: getVelocityFromUnitVector() Assumes you have your directional vector as a unit vector - if not then you will need this as well:
////////////////////////
// UNIT VECTOR
function unitVector2( v as tVect2 )
local r as tVect2
l# = length2( v )
r.x = v.x/l#
r.y = v.y/l#
endfunction r
and this:
/////////////////////////
// VECTOR LENGTH
function length2( v as tVect2 )
d# = sqrt( (v.x*v.x) + (v.y*v.y) )
endfunction d#