# Direction of a vector

If I want a physics body to move in a particular direction that is decide by two other vec2’s. but the velocity of the object I want to move is decided by me then how can I find the direction of the vector formed by the other two vectors. I tried this but it only gave me four direction, ofcourse because the velocities would be + or - 100 depending on the value of math.abs(v3.x or v3.y)

``````
--# Main
function setup()
b = physics.body(CIRCLE,10)
b.x = WIDTH/2
b.y = HEIGHT/2
physics.gravity(0,0)
end

function draw()
background(255, 255, 255, 255)
fill(0, 0, 0, 255)
ellipse(b.x,b.y,20)
v1 = vec2(b.x,b.y)
end

function touched(touch)
tx = touch.x
ty = touch.y
if touch.state == BEGAN then
v2 = vec2(tx,ty)
v3 = v2-v1
b.linearVelocity = vec2(100*v3.x/math.abs(v3.x),100*v3.y/math.abs(v3.y))
end
end
``````

An easy way to do this would be `b.linearVelocity = v3:normalize() * 100`.

Thanks worked out. But what does normalize mean out here? And what if I want to do with position like this

``````
--# Main

--# Main
function setup()
b = physics.body(CIRCLE,10)
b.x = WIDTH/2
b.y = HEIGHT/2
physics.gravity(0,0)
end

function draw()
background(255, 255, 255, 255)
fill(0, 0, 0, 255)
ellipse(b.x,b.y,20)
v1 = vec2(WIDTH/2,HEIGHT/2)
end

function touched(touch)
tx = touch.x
ty = touch.y
if touch.state == BEGAN then
v2 = vec2(tx,ty)
v3 = v2-v1
b.x = WIDTH/2 + v3.x/math.abs(v3.x)*100
b.y = HEIGHT/2  +  v3.y/math.abs(v3.y)*100
end
end
``````

Without making it too complicated, normalize shortens the vector so the magnitude (length) of the vector is 1. It “compresses” the vector while retaining its direction. Its useful for getting the angle of a vector.
Quick Tip, if you actually want the angle of a vector (in radians), try `vec2(0, 1):atan2(v.y, v.x)`, its helpful if you want to rotate vectors.
There are some handy vector guides all over the internet, its always nice to have a bit of a background with them.

Thanks @Jordan found a solution to my problem.