   Angle between two 2D points
  I'm trying to find the angle between two points in 2D, A and B.A is the location of a sprite, and B is the location of the mouse. I want to set the rotation of the sprite to the angle between the two points, so that the sprite appears to follow the mouse.I've been told that the dot product of two unit vectors returns the cosine of the angle between them, in the range -1 to 1, so the angle between the vectors must be...theta = acos(A.x * B.x + A.x * B.y)theta of course, is represented in radians. Now, the library I'm using is SFML, which requires that the angle for the sprite be passed to it in degrees, so it's as simple as Sprite::SetRotation(theta * 180.0f / PI), but the problem is, acos() seems to only be returning a value in the range 0 to PI/2 radians aka 0 to 90 degrees. How do I get an angle in the range 0 - 360 instead?   
float CMath::Angle( const CPoint* a, const CPoint* b){return ToDegrees( atan2( b->y - a->y, b->x - a->x ) );}float CMath::Angle( const CPoint* b){CPoint a(0,0,0);return Angle( &a, b );}float CMath::ToDegrees( float radians ){return radians * DEGREES_PER_RADIAN;}float CMath::ToRadians( float degrees ){return degrees * RADIANS_PER_DEGREE;};  haha, I suppose that will do it :)I was just curious as to how to do it using the dot product. I'm still interested to hear if someone knows the answer.Thanks for the speedy reply shadowcomplex :)   ;  How exactly do you define "angle between points"?Points are dimensionless entities with no direction in any n-space. The only sane measure between two points that I am aware of (at 10 in the morning) is distance.Possibly you mean angle between vectors?   ;  phresnel, I'm guessing that you mean that there's not such thing as angle between points on a 1D line... I would have thought specifying points in 2D space would have made it obvious that I meant 2D vectors :)   ;  It's off of the top of my head, but I'm believe it is correct. Test it though to make sure :)As for using acos, check here:http://www.cppreference.com/wiki/c/math/acosYou can use it but you need one more logic step afterwards to determine if your result should be positive or negative (which you can then calc out of 360). I find the atan2 solution to be cleaner, personally.   ;Quote:Original post by phresnelHow exactly do you define "angle between points"?Points are dimensionless entities with no direction in any n-space. The only sane measure between two points that I am aware of (at 10 in the morning) is distance.Possibly you mean angle between vectors?Often (and incorrectly so), points and vectors are used interchangeably in game dev, especially 2D game dev. Basically considering a point to be a vector originating from the origin. I've seen this from indies, hobbyists, and commercial shops :)This becomes a nuisance eventually, though, with "w" values. For the most part, 2D games can save on some code by having a joint "point"/"vector" class, even though it is amathematically incorrect model :DSo in the OP's case, it's really mapping one origin vector to another and determine the angle between them.   ;Quote:Original post by shadowcomplexQuote:Original post by phresnelHow exactly do you define "angle between points"?Points are dimensionless entities with no direction in any n-space. The only sane measure between two points that I am aware of (at 10 in the morning) is distance.Possibly you mean angle between vectors?Often (and incorrectly so), points and vectors are used interchangeably in game dev, especially 2D game dev. Basically considering a point to be a vector originating from the origin. I've seen this from indies, hobbyists, and commercial shops :)This becomes a nuisance eventually, though, with "w" values. For the most part, 2D games can save on some code by having a joint "point"/"vector" class, even though it is amathematically incorrect model :DSo in the OP's case, it's really mapping one origin vector to another and determine the angle between them.I think it is only beneficial to seperate those models (and comes at no extra runtime cost), as I made the experience that it makes code clearer (i.e. intentions) and less error prone (operations that don't make sense are forbidden). Some operations are also distinct, dependent on whether the underlying concept is point, vector, or normal.As you see, it already confused me to see some angle between points, which only makes sense if we assume some coordinate origin to both. To give an example of how I am used to it:   Point A, B;   ...   Vector direction = B-A;   float length = direction.length();   Point newP = A + direction * 3;Point+Point is not defined, Point-Point yields a Vector, Point[+-]Vector yields a new Point, et cetera. In picogen, the distinction is important for yet another reason: Points and Vectors are allowed to use different scalar types. I need this so that I can use fixed-point arithmetic for points, but floating point math for directions. Thanks to that distinction and the thorough constraints upon Points (operator+, operator-, distance), only the most basic fixed point math is needed (addition, subtraction, comparison)....Probably I am just too drilled by writing ray tracers, where the mathematical model is often common ;)   ;Quote:Original post by phresnelI think it is only beneficial to seperate those models (and comes at no extra runtime cost), as I made the experience that it makes code clearer (i.e. intentions) and less error prone (operations that don't make sense are forbidden). Some operations are also distinct, dependent on whether the underlying concept is point, vector, or normal.As you see, it already confused me to see some angle between points, which only makes sense if we assume some coordinate origin to both. To give an example of how I am used to it:   Point A, B;   ...   Vector direction = B-A;   float length = direction.length();   Point newP = A + direction * 3;Point+Point is not defined, Point-Point yields a Vector, Point[+-]Vector yields a new Point, et cetera. In picogen, the distinction is important for yet another reason: Points and Vectors are allowed to use different scalar types. I need this so that I can use fixed-point arithmetic for points, but floating point math for directions. Thanks to that distinction and the thorough constraints upon Points (operator+, operator-, distance), only the most basic fixed point math is needed (addition, subtraction, comparison)....Probably I am just too drilled by writing ray tracers, where the mathematical model is often common ;)No doubt, I agree absolutely. I've worked with systems using both approaches and found it's only sane to seperate them in large scale, math heavy projects. Of course, if I feel like writing a 2D shooter in a weekend, it's fun to pretend to add two points together :D;  Sorry, but I dont understand the distinction between a vector and a point. Isn't a point just a vector from <0, 0> ?   