I have an svg line that is drawn based on the (x, y) coordinates of 2 separate points. I want to take that drawn line and use the Math.Atan2 method to find it's angle.
Ie:
Above the center line = positive angle
Below the center line = negative angle
For my application, there will be no scenario where the points (a, b) will be on the same horizontal side. So the liner will always cross the imaginary vertical(y axis) centerline.
I have my functions working right now, but for some reason, the angle seems off, as well as being inversed. I stumbled upon this method after going down a rabbit hole of trying to do this with Pythagorean theorem, but this seems like a more out-of-the-box solution.
Am I misunderstanding how Math.Atan2 is supposed to work?
const getDegreeOfLine = (pointa, pointb) => {
p1 = pointa.getBoundingClientRect();
p2 = pointb.getBoundingClientRect();
return Math.floor(Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI);
}
Is the answer as simple as just inversing the returned result?