Monday, July 27, 2009

assignment 01B-Shi Xinyu




###############################################################
## Assignment 01
## Pof.Daniel da Rocha
## Student.SHI Xinyu
###############################################################

# logic
# 1) creste an initial square
# 2) find these two points (pocA & pocB) for rotate the square:
# 1) get current line
# 2) use pointOnCurve find the four points of the square
# 3) use the formula to find the pocA or pocB
# 1) if this is even number times, find pocA as rotation piont
# 2) if this is odd number times, find pocB as rotation piont
# 3) select the initail square
# 4) copy & rotate the square by pocA or pocB
# 5) select the last square and run this again

import maya.cmds as cmds

# creating initial square
mySquare = cmds.nurbsSquare(sl1=6,sl2=20)

def realRecursionOpt2(iterations):
#select mySquare
cmds.select( cl=1 )
cmds.select( mySquare )
mySquareNew = cmds.duplicate( mySquare )

sides = cmds.filterExpand( sm=9 )

#create a list to store the positions
positions = []
for i in range( len(sides) ):
pos = cmds.pointPosition( sides[i] +".cv[0]" )
positions.append(pos)
print positions

Xa = ((positions[1][0] + positions[2][0])/2 + positions[0][0])/2
Ya = ((positions[1][1] + positions[2][1])/2 + positions[0][1])/2
Za = ((positions[1][2] + positions[2][2])/2 + positions[0][2])/2

Xb = ((positions[1][0] + positions[2][0])/2 + positions[3][0])/2
Yb = ((positions[1][1] + positions[2][1])/2 + positions[3][1])/2
Zb = ((positions[1][2] + positions[2][2])/2 + positions[3][2])/2

if iterations/2 ==0:
cmds.rotate( 0,0,30, pivot=(Xa, Ya, Za) )
else:
cmds.rotate( 0,0,30, pivot=(Xb, Yb, Zb) )

mySquare = mySquareNew

#recursion part
if iterations ==0:
return "Done"
else:
iterations -=1
realRecursionOpt2(iterations)

realRecursionOpt2(1)

No comments:

Post a Comment