from math import * def sph_to_rect(r, t, p): def dtor(d): return d*pi/180.0 t = dtor(t) p = dtor(p) x = r * sin(p) * cos(t) y = r * sin(p) * sin(t) z = r * cos(p) return x, y, z def hemisphere (r): x,y,z = sph_to_rect(r, 0, 90) print "g01 x%f y%f z%f f20" % (x,y,z) old_x, old_y, old_z = x,y,z for phi in range(90, 181): p = phi if phi%2 == 0: p = -phi x,y,z = sph_to_rect(r,0,p) print "g02 x%f y%f z%f i%f j%f f20" % \ (x,y,z,(x-old_x)/2,(y-old_y)/2) old_x, old_y, old_z = x,y,z hemisphere(1.0) print "M02"