python 计算斜率

 

    p1 = [1, 2]
    p2 = [3, 4]

    xielv = abs((p1[1] - p2[1]) / (p1[0] - p2[0] + 1e-5))
    if xielv > 0.25 and xielv < 2:
        print(xielv)

 

根据斜率求角度:

import math

if __name__ == '__main__':

    p1 = [1, 2]
    p2 = [3, 4]

    xielv = abs((p1[1] - p2[1]) / (p1[0] - p2[0] + 1e-5))
    if xielv > 0.25 and xielv < 2:
        print(xielv)

        print(math.atan(xielv))
        print(math.degrees(math.atan(xielv)))

 

你可能感兴趣的:(python宝典)