Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- out = "sphere.stl"
- f = open(out, 'w')
- n = 10
- m = 20
- dtheta = 2.0 * math.pi / m
- dphi = 1.0 * math.pi / n
- f.write("solid Something (Meshed)\n")
- for i in range(0, m):
- theta = 2.0 * math.pi * i * 1.0 / m
- ct = math.cos(theta)
- st = math.sin(theta)
- ct1 = math.cos(theta + dtheta)
- st1 = math.sin(theta + dtheta)
- for j in range(0, n):
- phi = math.pi * j * 1.0 / n - 0.5 * math.pi
- cp = math.cos(phi)
- sp = math.sin(phi)
- cp1 = math.cos(phi + dphi)
- sp1 = math.sin(phi + dphi)
- f.write("\tfacet normal %.6f %.6f %.6f\n" % (ct * cp, st * cp, sp))
- f.write("\t\touter loop\n")
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct * cp, st * cp, sp))
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct * cp1, st * cp1, sp1))
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct1 * cp, st1 * cp, sp))
- f.write("\t\tendloop\n")
- f.write("\tendfacet\n")
- f.write("\tfacet normal %.6f %.6f %.6f\n" % (ct * cp, st * cp, sp))
- f.write("\t\touter loop\n")
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct1 * cp1, st1 * cp1, sp1))
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct * cp1, st * cp1, sp1))
- f.write("\t\t\tvertex %.6f %.6f %.6f\n" % (ct1 * cp, st1 * cp, sp))
- f.write("\t\tendloop\n")
- f.write("\tendfacet\n")
- f.write("endsolid Mesh\n")
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement