SFML community forums

Help => General => Topic started by: KarmaKilledtheCat on November 10, 2013, 04:51:40 am

Title: Calculating an angle from the points of a line
Post by: KarmaKilledtheCat on November 10, 2013, 04:51:40 am
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 (these lines are sf::Lines vertex arrays). 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?
Title: Re: Calculating an angle from the points of a line
Post by: zsbzsb on November 10, 2013, 05:00:04 am
So did you every try google (http://lmgtfy.com/?q=angle+between+points)? This isn't specific to SFML and is something you should try first searching for.
Title: Re: Calculating an angle from the points of a line
Post by: Nexus on November 10, 2013, 12:10:52 pm
Using Thor.Vectors (http://www.bromeon.ch/libraries/thor/v2.0/doc/_vector_algebra2_d_8hpp.html):
sf::Vector2f x, p, q;
// x is the point on both lines, q and p are points on either line

float angle = thor::signedAngle(p - x, q - x);