Created
November 8, 2014 18:29
-
-
Save anonymous/5b00d6b3502ceda7b270 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
primops = lambda: None | |
primops.TETRAEDER_TOP = 0 | |
primops.TETRAEDER_EDGE = 1 | |
primops.TETRAEDER_FACE = 2 | |
primops.OCTRAEDER_TOP = 3 | |
primops.OCTRAEDER_EDGE = 4 | |
primops.OCTRAEDER_FACE = 5 | |
primops.ICOSAEDER_TOP = 6 | |
primops.ICOSAEDER_EDGE = 7 | |
primops.ICOSAEDER_FACE = 8 | |
primops.TETRAEDER_TOP = 9 | |
class HedronScript(SvScriptSimpleGenerator): | |
@staticmethod | |
def make_tetraeder(which, top_x, top_y, top_z, scale): | |
x = top_x | |
y = top_y | |
z = top_z | |
# default tetraeder_top | |
vertskeleton = [(0.0 + x, 0.0 + y, 1.73205080757 + z), | |
(0.0, -1.63299316185, -0.577350269185), | |
(1.41421356237, 0.816496580927, -0.57735026919), | |
(-1.41421356237, 0.816496580927, -0.57735026919)] | |
if which == primops.TETRAEDER_EDGE: | |
vertskeleton = [(x, -1.41421356237 + y, 1.0 + z), | |
(x, 1.41421356237 + y, 1.0 + z), | |
(1.41421356237, 0.0, -1.0), | |
(-1.41421356237, 0.0, -1.0)] | |
elif which == primops.TETRAEDER_FACE: | |
vertskeleton = [(-1.41421356237 + x, -0.816496580927 + y, 0.57735026919 + z), | |
(1.41421356237 + x, -0.816496580927 + y, | |
0.57735026919 + z), | |
(x, 1.63299316185 + y, 0.577350269185 + z), | |
(0.0, 0.0, -1.73205080757)] | |
elif which == primops.OCTRAEDER_TOP: | |
vertskeleton = [(0.0 + x, 0.0 + y, 1.0 + z), | |
(0.0, 1.0, 0.0), | |
(-1.0, 0.0, 0.0), | |
(0.0, -1.0, 0.0), | |
(1.0, 0.0, 0.0), | |
(0.0, 0.0, -1.0)] | |
elif which == primops.OCTRAEDER_EDGE: | |
vertskeleton = [(0.0 + x, -0.707106781187 + y, 0.707106781187 + z), | |
(0.0 + x, 0.707106781187 + y, 0.707106781187 + z), | |
(1.0, 0.0, 0.0), | |
(-1.0, 0.0, 0.0), | |
(0.0, -0.707106781187, -0.707106781187), | |
(0.0, 0.707106781187, -0.707106781187)] | |
elif which == primops.OCTRAEDER_FACE: | |
vertskeleton = [(0.408248458663 + x, -0.707106781187 + y, 0.577350150255 + z), | |
(0.408248458663 + x, 0.707106781187 + y, | |
0.577350150255 + z), | |
(-0.816496412728 + x, 0.0 + y, 0.577350507059 + z), | |
(-0.408248458663, - | |
0.707106781187, -0.577350150255), | |
(0.816496412728, 0.0, -0.577350507059), | |
(-0.408248458663, 0.707106781187, -0.577350150255)] | |
elif which == primops.ICOSAEDER_TOP: | |
vertskeleton = [(0.0 + x, 0.0 + y, 0.587785252292 + z), | |
(0.0, -0.525731096637, 0.262865587024), | |
(0.5, -0.162459832634, 0.262865565628), | |
(0.309016994375, 0.425325419658, 0.262865531009), | |
(-0.309016994375, 0.425325419658, 0.262865531009), | |
(-0.5, -0.162459832634, 0.262865565628), | |
(0.309016994375, -0.425325419658, -0.262865531009), | |
(0.5, 0.162459832634, -0.262865565628), | |
(0.0, 0.525731096637, -0.262865587024), | |
(-0.5, 0.162459832634, -0.262865565628), | |
(-0.309016994375, - | |
0.425325419658, -0.262865531009), | |
(0.0, 0.0, -0.587785252292)] | |
elif which == primops.ICOSAEDER_EDGE: | |
vertskeleton = [(x, 0.309016994375 + y, 0.5 + z), | |
(x, -0.309016994375 + y, 0.5 + z), | |
(-0.5, 0, 0.309016994375), | |
(0.5, 0, 0.309016994375), | |
(-0.309016994375, -0.5, 0), | |
(0.309016994375, -0.5, 0), | |
(0.309016994375, 0.5, 0), | |
(-0.309016994375, 0.5, 0), | |
(-0.5, 0, -0.309016994375), | |
(0.5, 0, -0.309016994375), | |
(0, 0.309016994375, -0.5), | |
(0, -0.309016994375, -0.5)] | |
elif which == primops.ICOSAEDER_FACE: | |
vertskeleton = [(-0.17841104489 + x, 0.309016994375 + y, 0.46708617948 + z), | |
(-0.17841104489 + x, -0.309016994375 + y, | |
0.46708617948 + z), | |
(0.35682208977 + x, y, 0.467086179484 + z), | |
(-0.57735026919, 0.0, 0.110264089705), | |
(-0.288675134594, -0.5, -0.11026408971), | |
(0.288675134594, -0.5, 0.11026408971), | |
(0.57735026919, 0.0, -0.110264089705), | |
(0.288675134594, 0.5, 0.11026408971), | |
(-0.288675134594, 0.5, -0.11026408971), | |
(-0.35682208977, 0.0, -0.467086179484), | |
(0.17841104489, -0.309016994375, -0.46708617948), | |
(0.17841104489, 0.309016994375, -0.46708617948)] | |
return (np.array(vertskeleton)*scale).tolist() | |
@staticmethod | |
def make_edges(which, top_x, top_y, top_z, scale): | |
edgeskeleton = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [1, 3]] | |
if which > 2 and which < 6: # octaeder | |
edgeskeleton = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [2, 4], | |
[3, 4], [1, 3], [1, 5], [2, 5], [3, 5], [4, 5]] | |
if which == 5: | |
edgeskeleton = [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [2, 3], | |
[3, 4], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5]] | |
elif which == 6: # icosaeder | |
edgeskeleton = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [3, 4], [4, 5], [5, 1], | |
[1, 6], [2, 6], [2, 7], [3, 7], [3, 8], [4, 8], [4, 9], [5, 10], | |
[1, 10], [6, 7], [7, 8], [8, 9], [9, 10], [10, 6], [6, 11], [7, 11], | |
[8, 11], [9, 11], [10, 11]] | |
elif which == 7: | |
edgeskeleton = [[0, 1], [0, 7], [0, 2], [1, 2], [1, 4], [1, 5], [1, 3], [0, 3], | |
[0, 6], [2, 7], [2, 8], [2, 4], [4, 5], [3, 5], [3, 9], [3, 6], | |
[6, 7], [7, 10], [7, 8], [4, 8], [4, 11], [5, 11], [5, 9], [6, 9], | |
[6, 10], [8, 10], [8, 11], [9, 11], [9, 10], [10, 11]] | |
elif which == 8: | |
edgeskeleton = [[0, 1], [2, 1], [2, 0], [0, 3], [1, 3], [1, 4], [1, 5], [2, 5], | |
[2, 6], [2, 7], [0, 7], [0, 8], [3, 9], [3, 4], [5, 4], [5, 10], [5, 6], | |
[7, 6], [7, 11], [7, 8], [3, 8], [4, 9], [4, 10], [6, 10], [6, 11], | |
[8, 11], [8, 9], [9, 10], [11, 10], [11, 9]] | |
return edgeskeleton | |
@staticmethod | |
def make_faces(which, top_x, top_y, top_z, scale): | |
faceskeleton = [[0, 1, 2], [0, 2, 3], [0, 1, 3], [1, 2, 3]] | |
if which > 2 and which < 6: # octaeder | |
faceskeleton = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 1], | |
[1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 1, 5]] | |
if which == 4: | |
faceskeleton = [[0, 1, 2], [0, 1, 3], [0, 2, 4], [1, 2, 5], | |
[1, 3, 5], [0, 3, 4], [2, 4, 5], [3, 4, 5]] | |
elif which == 5: | |
faceskeleton = [(0, 1, 2), (0, 3, 4), (0, 1, 4), (1, 4, 5), | |
(2, 1, 5), (2, 3, 5), (0, 2, 3), (3, 4, 5)] | |
elif which == 6: # icosaeder | |
faceskeleton = [[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [1, 2, 6], | |
[2, 6, 7], [2, 3, 7], [3, 7, 8], [3, 4, 8], [4, 8, 9], [4, 5, 9], | |
[5, 9, 10], [5, 1, 10], [1, 10, 6], [6, 7, 11], [7, 8, 11], | |
[8, 9, 11], [9, 10, 11], [10, 6, 11]] | |
elif which == 7: | |
faceskeleton = [[0, 1, 2], [0, 1, 3], [0, 2, 7], [1, 2, 4], [1, 4, 5], [1, 3, 5], | |
[0, 3, 6], [0, 6, 7], [2, 7, 8], [2, 4, 8], [3, 5, 9], [3, 6, 9], | |
[7, 8, 10], [4, 8, 11], [4, 5, 11], [5, 9, 11], [6, 9, 10], | |
[6, 7, 10], [8, 10, 11], [9, 10, 11]] | |
elif which == 8: | |
faceskeleton = [[2, 0, 1], [0, 1, 3], [2, 1, 5], [2, 0, 7], [1, 3, 4], [1, 5, 4], | |
[2, 5, 6], [2, 7, 6], [0, 7, 8], [0, 3, 8], [3, 4, 9], [5, 4, 10], | |
[5, 6, 10], [7, 6, 11], [7, 8, 11], [3, 8, 9], [4, 9, 10], [6, 11, 10], | |
[8, 11, 9], [11, 9, 10]] | |
return faceskeleton | |
inputs = [('s', "which", 0), | |
('s', "top_x", 0.1), | |
('s', "top_y", 0.1), | |
('s', "top_z", 0.1), | |
('s', 'scale', 0.1)] | |
outputs = [("v", "Verts", "make_tetraeder"), | |
("s", "Edges", "make_edges"), | |
("s", "Faces", "make_faces")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment