def generate_polygon_on_xz_side_length(edges,side_length,offset=0) : ''' Return an polygon on plan XZ: with edges edges from length side_length, with offset offset. z / _____/____x / / plan XZ. ''' angle=360.0/side_length polygon=[] # Polygon vertice container. scale=360.0/edges # Computing of the angle separating 2 points from the polygon. start_vertex1=Vertex(-side_length/2.,0.0,0) start_vertex2=Vertex(side_length/2.,0.0,0) point_to_rotate=start_vertex1 rotate_point=start_vertex2 polygon.append(point_to_rotate) polygon.append(rotate_point) i=2 while i < edges : vertex=rotate_on_xz(rotate_point,abs(180-scale),point_to_rotate) point_to_rotate=rotate_point rotate_point=vertex polygon.append(vertex) i += 1 center=get_center_from_polygon(polygon) # Compute polygon center. tmp=[] for v in polygon : # Translate polygon vertices so as his center is the display center. tmp.append(translate(v,-center.wx,-center.wy,-center.wz)) if offset : offset_set=[] for v in tmp : offset_set.append(rotate_y(v,offset)) tmp=offset_set polygon=tmp return polygon
def generate_toros(base,base_radius,toros_radius) : ''' Generate an toros in relationship to the given settings: base: the toros basis polygon. base_radius: the toros basis polygon radius. toros_radius: the toros radius (without the base polygon radius). and return an sequence of polygons base from the toros. ''' base_polygon=generate_polygon_on_yz_radius(base,base_radius,Vertex(0.,0.,0.)) i=0 toros=[] while i < 360.0 : polygon=[] for v in base_polygon : vertex=rotate_y(translate(v,0.0,0.0,toros_radius),i) polygon.append(vertex) i += 360.0/base toros.append(polygon) return toros
def generate_toros(base, base_radius, toros_radius): ''' Generate an toros in relationship to the given settings: base: the toros basis polygon. base_radius: the toros basis polygon radius. toros_radius: the toros radius (without the base polygon radius). and return an sequence of polygons base from the toros. ''' base_polygon = generate_polygon_on_yz_radius(base, base_radius, Vertex(0., 0., 0.)) i = 0 toros = [] while i < 360.0: polygon = [] for v in base_polygon: vertex = rotate_y(translate(v, 0.0, 0.0, toros_radius), i) polygon.append(vertex) i += 360.0 / base toros.append(polygon) return toros
def generate_polyhedron_26_faces(side_length): ''' Generate an 26 faces polyhedron from the given side length and return an array of triangles and an array of quads composing the 26 faces of the polyhedron. ''' # Generation of octogons, bases of the 32 polyhedron mesh. octogon1 = generate_polygon_on_xy_side_length(8, side_length) octogon2 = generate_polygon_on_xy_side_length(8, side_length) octogon3 = generate_polygon_on_xz_side_length(8, side_length) octogon4 = generate_polygon_on_xz_side_length(8, side_length) octogon5 = generate_polygon_on_yz_side_length(8, side_length) octogon6 = generate_polygon_on_yz_side_length(8, side_length) # Translation to construct the polyhedron mesh. res = [] for v in octogon1: res.append(translate(v, 0.0, 0.0, -side_length / 2.0)) octogon1 = res # Translation to construct the polyhedron mesh. res = [] for v in octogon2: res.append(translate(v, 0.0, 0.0, side_length / 2.0)) octogon2 = res # Translation to construct the polyhedron mesh. res = [] for v in octogon3: res.append(translate(v, 0.0, -side_length / 2.0, 0.0)) octogon3 = res # Translation to construct the polyhedron mesh. res = [] for v in octogon4: res.append(translate(v, 0.0, side_length / 2.0, 0.0)) octogon4 = res # Translation to construct the polyhedron mesh. res = [] for v in octogon5: res.append(translate(v, -side_length / 2.0, 0.0, 0.0)) octogon5 = res # Translation to construct the polyhedron mesh. res = [] for v in octogon6: res.append(translate(v, side_length / 2.0, 0.0, 0.0)) octogon6 = res # We construct the polyhedron quads: quads_xy = [] i = -1 while i < len(octogon1) - 1: # by iterating overs octogon1 and octogon2 # which are in the plan XY. # With clever indexing. quads = [] quads.append(octogon1[i]) quads.append(octogon1[i + 1]) quads.append(octogon2[i + 1]) quads.append(octogon2[i]) quads_xy.append(quads) i += 1 # We construct the polyhedron quads: quads_xz = [] i = -1 while i < len(octogon3) - 1: # by iterating overs octogon3 and octogon4 # which are in the plan XZ. # With clever indexing. quads = [] quads.append(octogon3[i]) quads.append(octogon3[i + 1]) quads.append(octogon4[i + 1]) quads.append(octogon4[i]) quads_xz.append(quads) i += 1 # We construct the polyhedron quads: quads_yz = [] i = -1 while i < len(octogon1) - 1: # by iterating overs octogon3 and octogon4 # which are in the plan XZ. # With clever indexing. quads = [] quads.append(octogon5[i]) quads.append(octogon5[i + 1]) quads.append(octogon6[i + 1]) quads.append(octogon6[i]) quads_yz.append(quads) i += 1 # Finally we keep only the needed quads. To not have doubles. polyhedron = [] for v in quads_xz: polyhedron.append(v) polyhedron.append(quads_xy[0]) polyhedron.append(quads_xy[1]) polyhedron.append(quads_xy[2]) polyhedron.append(quads_xy[4]) polyhedron.append(quads_xy[5]) polyhedron.append(quads_xy[6]) polyhedron.append(quads_yz[0]) polyhedron.append(quads_yz[2]) polyhedron.append(quads_yz[4]) polyhedron.append(quads_yz[6]) # Finally we construct the triangles of the polyhedron. triangle1 = [polyhedron[1][1], polyhedron[3][0], polyhedron[12][3]] triangle2 = [polyhedron[3][1], polyhedron[5][0], polyhedron[12][0]] triangle3 = [polyhedron[5][1], polyhedron[6][1], polyhedron[12][1]] triangle4 = [polyhedron[7][1], polyhedron[1][0], polyhedron[12][2]] triangle5 = [polyhedron[7][2], polyhedron[1][3], polyhedron[9][3]] triangle6 = [polyhedron[5][3], polyhedron[4][3], polyhedron[9][1]] triangle7 = [polyhedron[6][3], polyhedron[7][3], polyhedron[9][0]] triangle8 = [polyhedron[1][2], polyhedron[2][2], polyhedron[9][2]] return [ triangle1, triangle2, triangle3, triangle4, triangle5, triangle6, triangle7, triangle8 ], polyhedron
def generate_polyhedron_26_faces(side_length) : ''' Generate an 26 faces polyhedron from the given side length and return an array of triangles and an array of quads composing the 26 faces of the polyhedron. ''' # Generation of octogons, bases of the 32 polyhedron mesh. octogon1=generate_polygon_on_xy_side_length(8,side_length) octogon2=generate_polygon_on_xy_side_length(8,side_length) octogon3=generate_polygon_on_xz_side_length(8,side_length) octogon4=generate_polygon_on_xz_side_length(8,side_length) octogon5=generate_polygon_on_yz_side_length(8,side_length) octogon6=generate_polygon_on_yz_side_length(8,side_length) # Translation to construct the polyhedron mesh. res=[] for v in octogon1 : res.append(translate(v,0.0,0.0,-side_length/2.0)) octogon1=res # Translation to construct the polyhedron mesh. res=[] for v in octogon2 : res.append(translate(v,0.0,0.0,side_length/2.0)) octogon2=res # Translation to construct the polyhedron mesh. res=[] for v in octogon3 : res.append(translate(v,0.0,-side_length/2.0,0.0)) octogon3=res # Translation to construct the polyhedron mesh. res=[] for v in octogon4 : res.append(translate(v,0.0,side_length/2.0,0.0)) octogon4=res # Translation to construct the polyhedron mesh. res=[] for v in octogon5 : res.append(translate(v,-side_length/2.0,0.0,0.0)) octogon5=res # Translation to construct the polyhedron mesh. res=[] for v in octogon6 : res.append(translate(v,side_length/2.0,0.0,0.0)) octogon6=res # We construct the polyhedron quads: quads_xy=[] i=-1 while i < len(octogon1)-1 : # by iterating overs octogon1 and octogon2 # which are in the plan XY. # With clever indexing. quads=[] quads.append(octogon1[i]) quads.append(octogon1[i+1]) quads.append(octogon2[i+1]) quads.append(octogon2[i]) quads_xy.append(quads) i += 1 # We construct the polyhedron quads: quads_xz=[] i=-1 while i < len(octogon3)-1 : # by iterating overs octogon3 and octogon4 # which are in the plan XZ. # With clever indexing. quads=[] quads.append(octogon3[i]) quads.append(octogon3[i+1]) quads.append(octogon4[i+1]) quads.append(octogon4[i]) quads_xz.append(quads) i += 1 # We construct the polyhedron quads: quads_yz=[] i=-1 while i < len(octogon1)-1 : # by iterating overs octogon3 and octogon4 # which are in the plan XZ. # With clever indexing. quads=[] quads.append(octogon5[i]) quads.append(octogon5[i+1]) quads.append(octogon6[i+1]) quads.append(octogon6[i]) quads_yz.append(quads) i += 1 # Finally we keep only the needed quads. To not have doubles. polyhedron=[] for v in quads_xz : polyhedron.append(v) polyhedron.append(quads_xy[0]) polyhedron.append(quads_xy[1]) polyhedron.append(quads_xy[2]) polyhedron.append(quads_xy[4]) polyhedron.append(quads_xy[5]) polyhedron.append(quads_xy[6]) polyhedron.append(quads_yz[0]) polyhedron.append(quads_yz[2]) polyhedron.append(quads_yz[4]) polyhedron.append(quads_yz[6]) # Finally we construct the triangles of the polyhedron. triangle1=[polyhedron[1][1],polyhedron[3][0],polyhedron[12][3]] triangle2=[polyhedron[3][1],polyhedron[5][0],polyhedron[12][0]] triangle3=[polyhedron[5][1],polyhedron[6][1],polyhedron[12][1]] triangle4=[polyhedron[7][1],polyhedron[1][0],polyhedron[12][2]] triangle5=[polyhedron[7][2],polyhedron[1][3],polyhedron[9][3]] triangle6=[polyhedron[5][3],polyhedron[4][3],polyhedron[9][1]] triangle7=[polyhedron[6][3],polyhedron[7][3],polyhedron[9][0]] triangle8=[polyhedron[1][2],polyhedron[2][2],polyhedron[9][2]] return [triangle1,triangle2,triangle3,triangle4,triangle5,triangle6,triangle7,triangle8], polyhedron