Skip to content

Instantly share code, notes, and snippets.

@rockjail rockjail/
Last active Aug 29, 2015

What would you like to do?
# !/usr/bin/env python
# base on
# also because of
# main thread
# small changes to include the orientation
# eulerToMatrix function from here:
import lx
import math
# Given Euler agnles in radians, return a rotation matrix.
def eulerToMatrix (x=0.0, y=0.0, z=0.0, rotOrder='XYZ'):
cx = math.cos (x)
sx = -math.sin (x)
cy = math.cos (y)
sy = -math.sin (y)
cz = math.cos (z)
sz = -math.sin (z)
if rotOrder == 'XYZ':
return [[cy*cz, cy*sz, -sy],
[sx*sy*cz - cx*sz, sx*sy*sz + cx*cz, sx*cy],
[cx*sy*cz + sx*sz, cx*sy*sz - sx*cz, cx*cy]]
elif rotOrder == 'XZY':
return [[cy*cz, sz, -cz*sy],
[sx*sy - cx*cy*sz, cz*cx, cx*sy*sz + cy*sx],
[cy*sx*sz + cx*sy, -cz*sx, cx*cy - sx*sy*sz]]
elif rotOrder == 'YXZ':
return [[cy*cz - sx*sy*sz, cy*sz + cz*sx*sy, -cx*sy],
[-cx*sz, cx*cz, sx],
[cy*sx*sz + cz*sy, sy*sz - cy*cz*sx, cx*cy]]
elif rotOrder == 'YZX':
return [[cy*cz, cx*cy*sz + sx*sy, cy*sx*sz - cx*sy],
[-sz, cx*cz, cz*sx],
[cz*sy, cx*sy*sz - cy*sx, sx*sy*sz + cx*cy]]
elif rotOrder == 'ZXY':
return [[sx*sy*sz + cy*cz, cx*sz, cy*sx*sz - cz*sy],
[cz*sx*sy - cy*sz, cx*cz, sy*sz + cy*cz*sx],
[cx*sy, -sx, cx*cy]]
elif rotOrder == 'ZYX':
return [[cy*cz, cx*sz + cz*sx*sy, sx*sz - cx*cz*sy],
[-cy*sz, cx*cz - sx*sy*sz, cx*sy*sz + cz*sx],
[sy, -cy*sx, cx*cy]]
def SunFlower(num):
lx.eval(' Transform xfrm false {0.78 0.78 0.78} 1.0')
lyr = lx.eval('query layerservice layers ? main')
lx.eval('select.type vertex')
a = math.pi * (3 - math.sqrt(5))
for n in range(1, num, 1):
r = math.sqrt(n)
t = a * n
rotMat = [item for sublist in eulerToMatrix(y=t, rotOrder='ZXY') for item in sublist]
x = r * math.cos(t)
z = r * math.sin(t)
lx.eval(' %s %s %s' % (x, 0, z))
lx.eval('select.element %s vertex set %s'%(lyr,n-1))
for i,k in enumerate(rotMat):
lx.eval('vertMap.setValue transform {%s} {%s}'%(i,k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.