Last active
August 29, 2015 14:14
-
-
Save winobes/75efe8580b1fe02cc58f to your computer and use it in GitHub Desktop.
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
def simplex_points(n): | |
""" | |
Generates subtriangles of the 3d 0-1 simplex (tripples of tripples). | |
`n` is the number of triangles along an edge (so it total it generates a | |
number of subtriangles equal to the n'th triangular number) | |
""" | |
def down(x,y,z): | |
return (x+1, y, z-1) | |
def left(x,y,z): | |
return (x-1, y+1, z) | |
def triangle(fst,snd,trd): | |
def point(x,y,z): | |
return (x/n, y/n, z/n) | |
return (point(*fst),point(*snd),point(*trd)) | |
for i in range(1, n+1): | |
fst = ((n-i),0,i) | |
snd = down(*fst) | |
trd = left(*snd) | |
yield triangle(fst,snd,trd) | |
last_left = True | |
while not trd == ((n-i),i,0): | |
fst = snd | |
snd = trd | |
trd = down(*trd) if last_left else left(*trd) | |
last_left = not last_left | |
yield triangle(fst,snd,trd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment