def drawCoordinate():
'''
绘制三维的坐标系,并绘制由坐标轴构成的平面的网格,各个坐标轴的颜色以及由坐标轴所引出的网格线的颜色为:
x: (1.0, 0.0, 0.0)
y: (0.0, 1.0, 0.0)
z: (0.0, 0.0, 1.0)
:return:
'''
#设置网格线间的步长
step = 0.2
#设置网格线的数量、长度
line_num = 15
line_len = 4
grid_color = [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)]
glLineWidth(3)
origin = [0.0, 0.0, 0.0]
#画出xyz轴
for i in range(3):
tmp = [0.0, 0.0, 0.0]
tmp[i] = line_len*1.02
glColor3f(*grid_color[i])
glBegin(GL_LINES)
glVertex3f(*origin)
glVertex3f(*tmp)
glEnd()
# 画出由坐标轴构成的平面的网格
glLineWidth(1)
for i in range(3):
#每次把一个坐标轴上引出的网格线都画出来,所以起点都是一致的
start = [0.0, 0.0, 0.0]
glColor3f(*grid_color[i])
for j in range(line_num):
end = [0.0, 0.0, 0.0]
glBegin(GL_LINES)
start[i] = start[i] + step
end[i] = start[i]
for k in {0,1,2} - {i,}:
end[k] = line_len
glVertex3f(*start)
glVertex3f(*end)
end[k] = 0.0
glEnd()