使用python在极坐标中生成一条直线

在测试雷达时,往往需要测试雷达的数据是否准确,这时就需要在雷达图中显示一条标准的直线作为对比。

"create a wall"
import numpy as np
import matplotlib.pyplot as plt
import sys

def main(distance):
    theta = np.arange(-45 / 180 * np.pi, 45 / 180 * np.pi, 1 / 180 * np.pi)

    tmp = np.cos(theta)


    wall = distance / tmp
    with open("dis.csv",mode = 'w') as file:
        counter = 0
        s = ''
        for n in wall:
            s += str("%d,"%n)
            counter += 1

        while counter < 360:
            s += "0,"
            counter += 1

        file.write(s)
        file.close()
    lin = np.linspace(distance+1000,distance+1000,len(theta))

    plt.polar(theta, wall)
    plt.polar(theta, lin)
    plt.show()

if __name__ == "__main__":
    main(int(sys.argv[1]))

想生成一条3m的直线,只需要输入:

python buildwall.py 3000

即可

posted @ 2017-04-05 21:03  Weyne  阅读(1626)  评论(0编辑  收藏  举报