02262016 class assignment Junya Huang

02262016class3.jpg

02272016class1.jpg

 

import rhinoscriptsyntax as rs
import math

def initialcurve():
st = 0,0,0
ed = 10, 0,0
crvid = rs.AddLine(st, ed)
return crvid

def endingcondition(crvid):
st = rs.CurveStartPoint(crvid)
ed = rs.CurveEndPoint(crvid)
length = rs.Distance(st, ed)

if length > 1:
return True
else:
False

def dosomething(crvid):
pts = rs.DivideCurve(crvid, 3)
crv1= rs.AddLine(pts[0], pts[1])
crv2 = rs.AddLine(pts[1], pts[2])
crv3 = rs.AddLine(pts[1],pts[2])
crv4 = rs.AddLine(pts[2], pts[3])

center = pts[1]
angle = 60
crv2 = rs.RotateObject(crv2, center, angle)

center = pts[2]
angle = -60
crv3 = rs.RotateObject(crv3, center, angle)

rs.DeleteObject(crvid)

return crv1, crv2, crv3, crv4

def recursion(crvid):
cond = endingcondition(crvid)
newid = dosomething(crvid)

if cond == True:
recursion(newid[0])
recursion(newid[1])
recursion(newid[2])
recursion(newid[3])

def rotate():
crv = rs.AllObjects()
st = 0,0,0
ed = 10, 0,0
center = st
angle = 60
crv2 = rs.RotateObject(crv, center, angle, None, True)
center = ed
angle = -60
crv3 = rs.RotateObject(crv, ed, angle, None, True)
crv3 = rs.MirrorObjects(crv, st, ed, False)

def copy():
crv = rs.AllObjects()
st = 0,0,0
ed = 10, 0,0
y = math.radians(30)
y = math.tan(y)
ned = 10,10*y, 0
trans = rs.VectorSubtract(ned, st)
crv2 = rs.CopyObjects(crv, trans)

crv = rs.AllObjects()
y = math.radians(-30)
y = math.tan(y)
nst = ned
ned = 10,10*y, 0
trans = rs.VectorSubtract(ned, nst)
crv3 = rs.CopyObjects(crv, trans)
crv4 = rs.CopyObjects(crv, trans*2)

crv = rs.AllObjects()
nst = st
ned = 2*10, 0,0
trans = rs.VectorSubtract(ned, nst)
crv5 = rs.CopyObjects(crv, trans)

def main():
crvid = initialcurve()
recursion(crvid)
rotate()
copy()

main()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s