Find Inverse Tangent?
12,371
Use Math.atan()
function and then multiply it by Math.toDegrees()
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));
Author by
PLP123
Updated on June 04, 2022Comments
-
PLP123 almost 2 years
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.
-
PLP123 about 7 yearswhat do I put into the atan? is it all 3 x's and y's
-
Da Mahdi03 over 5 yearsThis is from ProcessingJS, not JavaScript, there is a difference!
-
Kevin Workman over 5 years@DaMahdi03 Yes, I know. Please notice the processing.js tag in the question.
-
Da Mahdi03 over 5 yearsMaybe the person writing the question didn't know too much about JavaScript?
-
Kevin Workman over 5 years@DaMahdi03 Sorry, I'm not sure what you're trying to tell me. The question was tagged with processing.js, so I answered with Processing.js. Seems pretty reasonable to me.