I am making a game and I am trying to rotate an image so that it is always pointing at the player. I have two lines, the first point of both of them is on the image and the second point of one line is on the last position of the player, and the second point of the other one is on the current position of the player. To rotate the image I need to get the angle between the two lines. Does anyone know how I can get that angle with only the points from the lines?
I think you are doing it the hard way, though, by bothering with the previous-position line. Typically the image rotation is specified in radians from the original, unrotated position. Just calculate the current angle to the player and plug in the new angle.
Otherwise, just find the difference between the new angle and the old angle.
To find the angle, remember the arctangent function.
Given:
^ y
|
| *
| /|
| / | a = atan2( y, x )
|/a |
---+----------> x
|
|
Keep in mind that you must make proper adjustments for each quadrant.
2D or 3D, the lengths of the sides of the triangle is all that is required.
A triangle is planar and the law of cosines would apply. http://en.wikipedia.org/wiki/Law_of_cosines