Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Calculating an angle from the points of a line  (Read 1517 times)

0 Members and 1 Guest are viewing this topic.

KarmaKilledtheCat

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Calculating an angle from the points of a line
« 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?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Calculating an angle from the points of a line
« Reply #1 on: November 10, 2013, 05:00:04 am »
So did you every try google? This isn't specific to SFML and is something you should try first searching for.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Calculating an angle from the points of a line
« Reply #2 on: November 10, 2013, 12:10:52 pm »
Using Thor.Vectors:
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);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything