find angle between x-axis and y=mx in javascript

The angle between the x-axis and a line with slope m is given by Math.atan(m). Here's how you can find it in JavaScript:

index.tsx
const m = 1.5; // example slope
const angle = Math.atan(m);
console.log(angle); // angle in radians
100 chars
4 lines

The angle will be in radians, so you might want to convert it to degrees using Math.degrees(angle) if necessary.

related categories

gistlibby LogSnag