Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Inverse Tangent?

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.

like image 956
PLP123 Avatar asked Feb 24 '17 14:02

PLP123


People also ask

How do you find the inverse tangent?

In a right-angled triangle, the tangent of an angle (θ) is the ratio of its opposite side to the adjacent side. i.e., tan θ = (opposite side) / (adjacent side). Then by the definition of inverse tan, the inverse tan formula is, θ = tan-1[ (opposite side) / (adjacent side) ] .

What is the inverse tangent?

The inverse tangent formula is used to find the angle when the side opposite to that angle and adjacent side are known to us. The inverse of Tangent is represented by arctan or tan-1. The trigonometric functions/ratios are: Sine.


1 Answers

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));
like image 102
Ionut Avatar answered Sep 19 '22 01:09

Ionut