def Elt(refpt,dir,data): xform = Transform(dir,rs.VectorRotate(dir,90,[0,0,1]),refpt) L = [] R = [] for point in data[2]: trans = rs.VectorTransform(point,xform) trans = rs.VectorAdd(trans,refpt) L.append(trans) for point in data[3]: trans = rs.VectorTransform(point,xform) trans = rs.VectorAdd(trans,refpt) R.append(trans) trans = rs.VectorTransform(data[4],xform) return [trans,L,R]
def Ending(refpt, dir, data): xform = Transform(dir, rs.VectorRotate(dir, 90, [0, 0, 1]), refpt) both = [] for point in data[2]: trans = rs.VectorTransform(point, xform) trans = rs.VectorAdd(trans, refpt) both.append(trans) L = [both[0], both[1]] R = [both[2], both[1]] trans = rs.VectorTransform(data[1], xform) return [trans, L, R]
def Start(refpt,dir,data): xform = Transform(rs.VectorReverse(dir),rs.VectorReverse(rs.VectorRotate(dir,90,[0,0,1])),refpt) both = [] for point in data[2]: trans = rs.VectorTransform(point,xform) trans = rs.VectorAdd(trans,refpt) both.append(trans) L = [both[1],both[2]] R = [both[1],both[0]] trans = rs.VectorTransform(data[1],xform) #'Special case here: return [rs.VectorReverse(trans),L,R]
def verticalRotate(matrix, vity): #Find angle of matrix' verticality v = RhinoScript.VectorTransform(upVctr, matrix) v = RhinoScript.VectorUnitize(v) angV = math.acos(math.sqrt(v.X^2 + v.Y^2)) #Add preset angle 'vity' times until completely vertical angNew = ang + vity*angle if ang > math.pi/2.0: ang = math.pi/2.0 elif ang < -math.pi/2.0: ang = -math.pi/2.0 #Compute the new "concrete" rotation angRot = angNew - angV orth = Rhino.Geometry.Vector3d.CrossProduct(v, upVctr) rotation = rotateAroundVector(orth,angRot) return rotation
elif c == ']': turtlePos = posStack.pop() rotationMatrix = rotationStack.pop() turtleRelOr = relOrientStack.pop() fwdVctr = fwdStack.pop() nodeNormal = nodeNormStack.pop() nodeOrthogonal = nodeOrthStack.pop() spokeCount = spokeStack.pop() verticality = vertStack.pop() depth = depth - 1 elif c == 'n': #flag for beginning a node spokeCount = 0 nodeNormal = fwdVctr nodeOrthogonal = orthVctr(nodeNormal) randomRotate = random()*2.0*math.pi nodeOrthogonal = RhinoScript.VectorTransform(nodeOrthogonal, rotateAroundVector(nodeNormal,randomRotate)) elif c == 'R': #node spoke rotate spokeCount = spokeCount + 1 for i in range(spokeCount): fwdVctr = RhinoScript.VectorTransform(nodeOrthogonal, rotateAroundVector(nodeNormal,phiangle)) randomRotate = math.acos(random()*math.pi)/2.0 fwdVctr = RhinoScript.VectorTransform(fwdVctr, rotateAroundVector(Rhino.Geometry.Vector3d.CrossProduct(fwdVctr,nodeNormal),randomRotate)) elif c == 'F': #find rotation matrix from old forward vector orthVctr = orthVector(fwdVctr) relativeRotation = RhinoScript.XformMultiply(rotateAroundVector(fwdVctr,turtleRelOr[0]), rotateAroundVector(orthVctr,turtleRelOr[1])) rotationMatrix = RhinoScript.XformMultiply(relativeRotation, rotationMatrix) rotationMatrix = verticalRotate(rotationMatrix, verticality) #find new forward vector from rotation matrix and scale fwdVctr = RhinoScript.VectorTransform(upVctr, rotationMatrix)