Functions and Variables
This is for exercise 2, the second exploration of transforming from 2D linework to 3D structure (although it is still linework)
The steps of the programming process:
1. define the components that decide the length of each line
2. define function windrose that generates the structure
3. in windrose, rotate lines to get new forms
4. ask user for the length of cardinal point, which changes the size of the structure
5. program for exceptions with message for user when line length is not correct
5. evoke function windrose
In the diagrams below, the length of cardinal point, which changes the size of the structure, changes from 1, 2, 3, 4, accordingly.
Here’s the code:
-
#link to the Rhino Function library import rhinoscriptsyntax as rs import math import random def windrose(intCardinals, dblCardLength, translation): ptL = dblCardLength /2 alpha = (math.radians(180)/intCardinals) ptX = ptL / math.tan(alpha) ptY = ptL / math.sin (alpha) #drafts one cardinal direction objCardinalPoint = rs.AddPolyline \ (([ptX,0,0],[0,ptX,0],[0,0,ptX],[ptY,0,0],[0,ptY,0])) lines = [] for i in range (1, intCardinals): angel = 360/ intCardinals new = rs.RotateObjects(objCardinalPoint, [0,0,0], angel * i, copy=True) lines.append (rs.ScaleObject(new, [0,0,0], [i,i,i])) return lines rs. DeleteObjects(rs.AllObjects()) dblMyCardLength = rs.GetReal \ ("Enter length of cardinal point", 4.0) intMyCardinals = 40 while (intMyCardinals < 2): Print ("That number is too short") intMyCardinals = rs.GetInteger ("Enter number of cardinal points", 10) LineWork = windrose(intMyCardinals,dblMyCardLength,[0,0,0])