Reputation: 4738
I would like to know 2 things about the struct Vector2 in XNA:
Thanks a lot in advance.
Kind Regards.
Josema.
Upvotes: 1
Views: 5751
Reputation: 56822
To calculate the direction (angle) of a vector most languages have an atan2(y,x) function.
Upvotes: 3
Reputation: 14077
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))
.
Upvotes: 3
Reputation: 14111
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.
Upvotes: 3
Reputation: 7541
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.
Upvotes: 2