Monday, May 20, 2013

Geometry: How to get the angle from a slope?


To get the angle from a slope,

First, you must need to identify the slope of a line.

To get the slope of a line, you need to use the formula dy/dx or

∆y/∆x as distance of y and distance of x.

That is,

m = y1-y2/x1-x2


To get the angle, you can use arctangent, the inverse of tan, as

tan -1 x = arctangent or arctan

so

angle = arctangent(m)

m = tangent(angle)

For example, in Python,


>>> math.atan(0.38)* 180/math.pi
20.80679101271123
>>> math.tan(20.80679101271123 * math.pi/180)
0.37999999999999995


math.atan and tan are in radians, so I convert them from radians to degrees or degrees to radians.



No comments:

Post a Comment