# Vector Problems

Hi I got some real vector noob problems:

I’m trying to create a Vector That points from the head of v(a) to head of v(b).

Like So:

``````var a = this.app.root.findByName("Box1").getPosition().clone();
var b = this.app.root.findByName("Box2").getPosition().clone();

a.sub(b);
this.app.renderLine(b, a, this.colorGreen);
``````

But when I try to visualize the vector by drawing it, is not what I envisioned, I would have expected it to be drawn from a to b.

but instead its drawn from origin (0,0) to b.

Try drawing same thing on the paper in 2D, and making math by hand, it will make clear what went wrong here

Basically:
`v = a - b` - this gives you the difference between two vectors.
a and b are the world points.

Then you got that v and drawing point from it, which is relative to b because you did sub, but other end of line you draw to world point b. I think you get confused with what your vectors/points are

If you draw line between two points p1 and p2 you probably will get what you need.
Pseudo code:

``````v = b - a;

p1 = a;
p2 = a + v;

drawLine(p1, p2);
``````

Thx Max!

Your code did work

Seems like there are some basics, I still need to figure our to apply my theoretical(limited) vector knowledge.

I had to learn all this stuff myself too.
It helps to play with paper and pencil a lot in 2 dimensions, same logic as with 3 dimensions.