Original file (5,120 × 2,880 pixels, file size: 6 KB, MIME type: application/sla)
This is a file from the
Wikimedia Commons. Information from its
description page there is shown below. Commons is a freely licensed media file repository. You can help. |
View First rhombic dodecahedron stellation.stl on viewstl.com
DescriptionFirst rhombic dodecahedron stellation.stl |
English: Stellated rhombic dodecahedron made of pyramids and half-cubes by CMG Lee. |
Date | |
Source | Own work |
Author | Cmglee |
#!/usr/bin/env python
header = 'Stellated rhombic dodecahedron made of pyramids and half-cubes by CMG Lee.'
import re, struct, math
def fmt(string): ## string.format(**vars()) using tags {expression!format} by CMG Lee
def f(tag): i_sep = tag.rfind('!'); return (re.sub('\.0+$', '', str(eval(tag1:-1])))
if (i_sep < 0) else ('{:%s}' % tagi_sep + 1:-1]).format(eval(tag1:i_sep])))
return (re.sub(r'(?<!{){[^{}]+}', lambda m:f(m.group()), string)
.replace('{{', '{').replace('}}', '}'))
def append(obj, string): return obj.append(fmt(string))
def tabbify(cellss, separator='|'):
cellpadss = list(rows) + '' * (len(max(cellss, key=len)) - len(rows)) for rows in cellss
fmts = '%%%ds' % (max([len(str(cell)) for cell in cols])) for cols in zip(*cellpadss)]
return '\n'.join([separator.join(fmts) % tuple(rows) for rows in cellpadss])
def hex_rgb(colour): ## convert [#]RGB to #RRGGBB and [#]RRGGBB to #RRGGBB
return '#%s' % (colour if len(colour) > 4 else ''.join([c * 2 for c in colour])).lstrip('#')
def viscam_colour(colour):
colour_hex = hex_rgb(colour)
colour_top5bits = int(colour_hexi:i+2], 16) >> 3 for i in range(1,7,2)]
return (1 << 15) + (colour_top5bits0 << 10) + (colour_top5bits1 << 5) + colour_top5bits2
def roundm(x, multiple=1):
if (isinstance(x, tuple)): return tuple(roundm(list(x), multiple))
elif (isinstance(x, list )): return roundm(x_i, multiple) for x_i in x
else: return int(math.floor(float(x) / multiple + 0.5)) * multiple
def flatten(lss): return l for ls in lss for l in ls
def rotate(facetss, degs): ## around x then y then z axes
(deg_x,deg_y,deg_z) = degs
(sin_x,cos_x) = (math.sin(math.radians(deg_x)), math.cos(math.radians(deg_x)))
(sin_y,cos_y) = (math.sin(math.radians(deg_y)), math.cos(math.radians(deg_y)))
(sin_z,cos_z) = (math.sin(math.radians(deg_z)), math.cos(math.radians(deg_z)))
facet_rotatess = []
for facets in facetss:
facet_rotates = []
for i_point in range(4):
(x, y, z) = facets3 * i_point + i_xyz for i_xyz in range(3)]
if (x is None or y is None or z is None):
facet_rotates += x, y, z
else:
(y, z) = (y * cos_x - z * sin_x, y * sin_x + z * cos_x) ## rotate about x
(x, z) = (x * cos_y + z * sin_y, -x * sin_y + z * cos_y) ## rotate about y
(x, y) = (x * cos_z - y * sin_z, x * sin_z + y * cos_z) ## rotate about z
facet_rotates += round(value, 9) for value in x, y, z]]
facet_rotatess.append(facet_rotates)
return facet_rotatess
def translate(facetss, ds): ## ds = (dx,dy,dz)
return facets[:3 + facets3 * i_point + i_xyz + dsi_xyz
for i_point in range(1,4) for i_xyz in range(3)]
for facets in facetss
## Add facets
facet_sidess = [[None,0,0, 0, 0,0, 20,20,-20, -20, 20,-20]]
facet_basess = [[None,0,0, -20,20,0, 20,20, 0, 20,-20, 0]]
facet_basess += rotate(facet_basess, (0,0,180))
facet_1_pyramidss = translate(facet_sidess, (0,0,-1))
facet_1_pyramidss += rotate(facet_1_pyramidss, (0,0,-90))
facet_1_pyramidss += rotate(facet_1_pyramidss, (0,0,180))
facet_1_pyramidss += translate(facet_basess, (0,0,-21))
facet_3_pyramidss = facet_1_pyramidss.copy()
facet_3_pyramidss += rotate(facet_1_pyramidss, (-90,0,0))
facet_3_pyramidss += rotate(facet_1_pyramidss, (0,90,0))
facet_sixth_cubess = facet_sidess.copy()
facet_sixth_cubess += rotate(facet_sixth_cubess, (0,0,-90))
facet_sixth_cubess += translate(facet_basess, (0,0,-20))
facet_half_cubess = facet_sixth_cubess.copy()
facet_half_cubess += rotate(facet_sixth_cubess, (-90,-90, 0))
facet_half_cubess += rotate(facet_sixth_cubess, ( 90, 0,90))
facetss = (rotate(translate(facet_3_pyramidss, (22,22,22)), (0,0,180)) +
translate(facet_half_cubess, (22,22,22)) )
facetss += rotate(facetss, (-90,0,0))
facetss += rotate(facetss, (180,0,0))
# facetss = [facets[:3] + facets[6:9] + facets[3:6] + facets[9:] for facets in facetss] ## flip
## Calculate normals
for facets in facetss:
if (facets0 is None or facets1 is None or facets2 is None):
us = facetsi_xyz + 9 - facetsi_xyz + 6 for i_xyz in range(3)]
vs = facetsi_xyz + 6 - facetsi_xyz + 3 for i_xyz in range(3)]
normals = us1*vs2 - us2*vs1], us2*vs0 - us0*vs2], us0*vs1 - us1*vs0]]
normal_length = sum([component * component for component in normals]) ** 0.5
facets[:3 = -round(component / normal_length, 10) for component in normals
print(tabbify([['N%s' % (xyz ) for xyz in list('xyz')] +
'%s%d' % (xyz, n) for n in range(3) for xyz in list('XYZ')] + 'RGB']] + facetss))
## Compile STL
outss = ([[('STL\n\n%-73s\n\n' % (header[:73])).encode('utf-8'), struct.pack('<L',len(facetss))]] +
[[struct.pack('<f',float(value)) for value in facets[:12]] +
struct.pack('<H',0 if (len(facets) <= 12) else
viscam_colour(facets12]))] for facets in facetss])
out = b''.join([bytes(out) for outs in outss for out in outs])
# out += ('\n\n## Python script to generate STL\n\n%s\n' % (open(__file__).read())).encode('utf-8')
print("# bytes:%d\t# facets:%d\ttitle:\"%-73s\"" % (len(out), len(facetss), header[:73]))
with open(__file__[:__file__.rfind('.')] + '.stl', 'wb') as f_out: f_out.write(out)
The uploader of this file has agreed to the Wikimedia Foundation 3D patent license: This file and any 3D objects depicted in the file are both my own work. I hereby grant to each user, maker, or distributor of the object depicted in the file a worldwide, royalty-free, fully-paid-up, nonexclusive, irrevocable and perpetual license at no additional cost under any patent or patent application I own now or in the future, to make, have made, use, offer to sell, sell, import, and distribute this file and any 3D objects depicted in the file that would otherwise infringe any claims of any patents I hold now or in the future. Please note that in the event of any differences in meaning or interpretation between the original English version of this license and a translation, the original English version takes precedence. |
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 22:18, 1 April 2018 | 5,120 × 2,880 (6 KB) | Cmglee | User created page with UploadWizard |
The following other wikis use this file:
Original file (5,120 × 2,880 pixels, file size: 6 KB, MIME type: application/sla)
This is a file from the
Wikimedia Commons. Information from its
description page there is shown below. Commons is a freely licensed media file repository. You can help. |
View First rhombic dodecahedron stellation.stl on viewstl.com
DescriptionFirst rhombic dodecahedron stellation.stl |
English: Stellated rhombic dodecahedron made of pyramids and half-cubes by CMG Lee. |
Date | |
Source | Own work |
Author | Cmglee |
#!/usr/bin/env python
header = 'Stellated rhombic dodecahedron made of pyramids and half-cubes by CMG Lee.'
import re, struct, math
def fmt(string): ## string.format(**vars()) using tags {expression!format} by CMG Lee
def f(tag): i_sep = tag.rfind('!'); return (re.sub('\.0+$', '', str(eval(tag1:-1])))
if (i_sep < 0) else ('{:%s}' % tagi_sep + 1:-1]).format(eval(tag1:i_sep])))
return (re.sub(r'(?<!{){[^{}]+}', lambda m:f(m.group()), string)
.replace('{{', '{').replace('}}', '}'))
def append(obj, string): return obj.append(fmt(string))
def tabbify(cellss, separator='|'):
cellpadss = list(rows) + '' * (len(max(cellss, key=len)) - len(rows)) for rows in cellss
fmts = '%%%ds' % (max([len(str(cell)) for cell in cols])) for cols in zip(*cellpadss)]
return '\n'.join([separator.join(fmts) % tuple(rows) for rows in cellpadss])
def hex_rgb(colour): ## convert [#]RGB to #RRGGBB and [#]RRGGBB to #RRGGBB
return '#%s' % (colour if len(colour) > 4 else ''.join([c * 2 for c in colour])).lstrip('#')
def viscam_colour(colour):
colour_hex = hex_rgb(colour)
colour_top5bits = int(colour_hexi:i+2], 16) >> 3 for i in range(1,7,2)]
return (1 << 15) + (colour_top5bits0 << 10) + (colour_top5bits1 << 5) + colour_top5bits2
def roundm(x, multiple=1):
if (isinstance(x, tuple)): return tuple(roundm(list(x), multiple))
elif (isinstance(x, list )): return roundm(x_i, multiple) for x_i in x
else: return int(math.floor(float(x) / multiple + 0.5)) * multiple
def flatten(lss): return l for ls in lss for l in ls
def rotate(facetss, degs): ## around x then y then z axes
(deg_x,deg_y,deg_z) = degs
(sin_x,cos_x) = (math.sin(math.radians(deg_x)), math.cos(math.radians(deg_x)))
(sin_y,cos_y) = (math.sin(math.radians(deg_y)), math.cos(math.radians(deg_y)))
(sin_z,cos_z) = (math.sin(math.radians(deg_z)), math.cos(math.radians(deg_z)))
facet_rotatess = []
for facets in facetss:
facet_rotates = []
for i_point in range(4):
(x, y, z) = facets3 * i_point + i_xyz for i_xyz in range(3)]
if (x is None or y is None or z is None):
facet_rotates += x, y, z
else:
(y, z) = (y * cos_x - z * sin_x, y * sin_x + z * cos_x) ## rotate about x
(x, z) = (x * cos_y + z * sin_y, -x * sin_y + z * cos_y) ## rotate about y
(x, y) = (x * cos_z - y * sin_z, x * sin_z + y * cos_z) ## rotate about z
facet_rotates += round(value, 9) for value in x, y, z]]
facet_rotatess.append(facet_rotates)
return facet_rotatess
def translate(facetss, ds): ## ds = (dx,dy,dz)
return facets[:3 + facets3 * i_point + i_xyz + dsi_xyz
for i_point in range(1,4) for i_xyz in range(3)]
for facets in facetss
## Add facets
facet_sidess = [[None,0,0, 0, 0,0, 20,20,-20, -20, 20,-20]]
facet_basess = [[None,0,0, -20,20,0, 20,20, 0, 20,-20, 0]]
facet_basess += rotate(facet_basess, (0,0,180))
facet_1_pyramidss = translate(facet_sidess, (0,0,-1))
facet_1_pyramidss += rotate(facet_1_pyramidss, (0,0,-90))
facet_1_pyramidss += rotate(facet_1_pyramidss, (0,0,180))
facet_1_pyramidss += translate(facet_basess, (0,0,-21))
facet_3_pyramidss = facet_1_pyramidss.copy()
facet_3_pyramidss += rotate(facet_1_pyramidss, (-90,0,0))
facet_3_pyramidss += rotate(facet_1_pyramidss, (0,90,0))
facet_sixth_cubess = facet_sidess.copy()
facet_sixth_cubess += rotate(facet_sixth_cubess, (0,0,-90))
facet_sixth_cubess += translate(facet_basess, (0,0,-20))
facet_half_cubess = facet_sixth_cubess.copy()
facet_half_cubess += rotate(facet_sixth_cubess, (-90,-90, 0))
facet_half_cubess += rotate(facet_sixth_cubess, ( 90, 0,90))
facetss = (rotate(translate(facet_3_pyramidss, (22,22,22)), (0,0,180)) +
translate(facet_half_cubess, (22,22,22)) )
facetss += rotate(facetss, (-90,0,0))
facetss += rotate(facetss, (180,0,0))
# facetss = [facets[:3] + facets[6:9] + facets[3:6] + facets[9:] for facets in facetss] ## flip
## Calculate normals
for facets in facetss:
if (facets0 is None or facets1 is None or facets2 is None):
us = facetsi_xyz + 9 - facetsi_xyz + 6 for i_xyz in range(3)]
vs = facetsi_xyz + 6 - facetsi_xyz + 3 for i_xyz in range(3)]
normals = us1*vs2 - us2*vs1], us2*vs0 - us0*vs2], us0*vs1 - us1*vs0]]
normal_length = sum([component * component for component in normals]) ** 0.5
facets[:3 = -round(component / normal_length, 10) for component in normals
print(tabbify([['N%s' % (xyz ) for xyz in list('xyz')] +
'%s%d' % (xyz, n) for n in range(3) for xyz in list('XYZ')] + 'RGB']] + facetss))
## Compile STL
outss = ([[('STL\n\n%-73s\n\n' % (header[:73])).encode('utf-8'), struct.pack('<L',len(facetss))]] +
[[struct.pack('<f',float(value)) for value in facets[:12]] +
struct.pack('<H',0 if (len(facets) <= 12) else
viscam_colour(facets12]))] for facets in facetss])
out = b''.join([bytes(out) for outs in outss for out in outs])
# out += ('\n\n## Python script to generate STL\n\n%s\n' % (open(__file__).read())).encode('utf-8')
print("# bytes:%d\t# facets:%d\ttitle:\"%-73s\"" % (len(out), len(facetss), header[:73]))
with open(__file__[:__file__.rfind('.')] + '.stl', 'wb') as f_out: f_out.write(out)
The uploader of this file has agreed to the Wikimedia Foundation 3D patent license: This file and any 3D objects depicted in the file are both my own work. I hereby grant to each user, maker, or distributor of the object depicted in the file a worldwide, royalty-free, fully-paid-up, nonexclusive, irrevocable and perpetual license at no additional cost under any patent or patent application I own now or in the future, to make, have made, use, offer to sell, sell, import, and distribute this file and any 3D objects depicted in the file that would otherwise infringe any claims of any patents I hold now or in the future. Please note that in the event of any differences in meaning or interpretation between the original English version of this license and a translation, the original English version takes precedence. |
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 22:18, 1 April 2018 | 5,120 × 2,880 (6 KB) | Cmglee | User created page with UploadWizard |
The following other wikis use this file: