Find Inverse Tangent?

PLP123 picture PLP123 · Feb 24, 2017 · Viewed 10.6k times · Source

I'm new to Javascript and I'm trying to use inverse tangent to find the angle in degrees between a line and the x axis on an elevated y. I don't see any command for it so I really need some help.

Answer

Ionut picture Ionut · Feb 24, 2017

Use Math.atan() function and then Math.toDegrees() multiply it by 180/Math.PI to convert radians to degrees Found the answer it here

Later edit:

Here is an example of angle calculation between a line defined by 2 points (A and B) and the X axis. The elevation of the second line (parallel with the X axis) is irrelevant since the angle stays the same.

 /*
 * Calculates the angle between AB and the X axis
 * A and B are points (ax,ay) and (bx,by)
 */
function getAngleDeg(ax,ay,bx,by) {
  var angleRad = Math.atan((ay-by)/(ax-bx));
  var angleDeg = angleRad * 180 / Math.PI;
  
  return(angleDeg);
}

console.log(getAngleDeg(0,1,0,0));