views:

316

answers:

5

Hi,

I would like to know 2 things about the struct Vector2 in XNA:

  1. Why does this struct only have X and Y instead of X,Y (origin) and X',Y' (destination)?
  2. How can I calculate the direction of a vector with only the X,Y?

Thanks a lot in advance.
Kind Regards.
Josema.

+13  A: 

The origin is usually assumed to be (0,0).

Amuck
Thanks for your clear answer.
Josema
...and based on this assumption, both direction AND length can be determined.
Peter Lillevold
+3  A: 

1) A vector does not need length.

2) The numbers themselves determine the direction of the vector. Think of the cartesian plane. If you have a negative x and a positive y, then you are going top left...positive x, positive y, top right...etc. etc.

Aaron
Thanks for your clear answer.
Josema
Not quite true... a vector has a length (norm) by definition. However, a vector does not need _location_ in terms of a coordinate system.
codekaizen
+3  A: 

The X and Y are not actually the coordinates of a point.

They are X-axis and Y-axis components of the vector. A vector by definition has no origin, it represents only direction and length, not position.

kek444
+2  A: 

Mathematically a vector has orientation (direction) and magnitude (length). It does not have position. When vectors are used in graphics programming to represent positions they are implicitly representing a point as an offset from the origin.

If you want to convert from a vector to an angle you can use simple trigonometry - the x and y components form two sides of a triangle and you can calculate the angle the vector makes with any axis. If you want to find the angle between two arbitrary vectors a and b it's acos(dot(a, b) / (length(a) * length(b)).

mattnewport
+2  A: 

To calculate the direction (angle) of a vector most languages have an atan2(y,x) function.

starblue