Mar 8, 2009 0
Mar 8, 2009 0
kristin koslowski (dragana + onur)
Feb 16, 2009 1
Student Scripts | abbe_bernal
Three very similar variations on a script written for Abbe and Bernal in Lonn Comb’s class. These scripts create a truss-like 3d pattern, with increasingly complex math-driven variations. They rely on 4 methods to do the bulk of the work, described below:
the function HynetCellPts, creates a collection of four points which makeup the basic module of a truss… it doesn’t draw anything to rhino, it just creates the points (as data) at a given location, and stores these points in an array.
the function HynetGridPts, calls upon this previous function, and creates a grid of modules at a particular scale and spacing…. again, it doesn’t draw anything, it simply creates the points and stores them in an array in a structured manner. can you figure out the structure of this array, and draw it in monkeybrainland?
the function Main, calls upon this previous function, and creates two grids of module points – one slightly higher than the other: arrPtsTop and arrPtsBtm. again, nothing is drawn to rhino, but the critical positions for the truss are figured out here and stored in two arrays. Then, finally, at the end of this function, the final method is called which draws elements to rhino based on these two arrays.
the function DrawHynetMatrix looks like the most complicated function in the lot, but in reality it’s job is the simplest. based on two arrays of module points (defined in functions above), this function draws the desired geometry to rhino. there’s alot of “weaving” going on here – figuring out which point on one module to connect to which point on the next – but conceptually, things are very straightforward.
Tags: Rhinoscript, structure, student script, tiling, trussFeb 16, 2009 0
Rhinoscript | Vector Utility Functions
Function VectorProjectedLength(arrSrc, arrDest) '' Returns the length of the vector which results from the projection of the source vector onto the destination vector VectorProjectedLength = Rhino.VectorDotProduct(arrSrc,Rhino.VectorUnitize(arrDest)) End Function
Function VectorProject(arrSrc, arrDest) ''Returns the vector which results from the projection of the source vector onto the destination vector VectorProject = VectorResize(arrDest,VectorProjectedLength(arrSrc, arrDest)) End Function
Function VectorResize(arrVec, dblSize) Dim v : v = Rhino.VectorUnitize(arrVec) VectorResize = Rhino.VectorScale(v,dblSize) End Function
Function Centroid(arrPts) Dim cent, n cent = array(0,0,0) For n=0 To Ubound(arrPts) cent = Rhino.VectorAdd(cent, arrPts(n)) Next cent = Rhino.VectorScale(cent, 1/(Ubound(arrPts)+1)) Centroid = cent End Function
Function PointInterpolate(arrPtA, arrPtB, t) Dim vec vec = Rhino.VectorCreate(arrPtB, arrPtA) vec = Rhino.VectorScale(vec,t) PointInterpolate = Rhino.PointAdd(arrPtA, vec) End Function
Function ScalePtsAboutCentroid(arrPts, scale) Dim cent, tVec cent = Centroid(arrPts) tVec = Rhino.VectorCreate(array(0,0,0), cent) Dim n For n=0 To Ubound(arrPts) arrPts(n) = Rhino.PointAdd(arrPts(n), tVec) arrPts(n) = Rhino.PointScale(arrPts(n), scale) arrPts(n) = Rhino.PointAdd(arrPts(n), Rhino.VectorReverse(tVec)) Next ScalePtsAboutCentroid = arrPts End Function
Function VectorCompare(arrVecA, arrVecB) '' compares two vectors, see if they are pointing basically the same way VectorCompare = False If (VectorProjectedLength(arrVecA, arrVecB) > 0 ) Then VectorCompare = True End Function
Function DistanceXY(arrPtA, arrPtB) DistanceXY = ( (arrPtA(0)-arrPtB(0))^2 + (arrPtA(1)-arrPtB(1))^2 )^0.5 End FunctionTags: Rhinoscript, sample script, utility, vector, vector math
Feb 15, 2009 0
Sunday Script | Cardioid
Option Explicit 'Script written by ksteinfe Call Cardioid() Sub Cardioid() ReDim arrPoints(50) Dim x,y,z Dim theta '' cardioid Dim r Dim n r = 1 For n=0 To 50 theta = (n/50)*Rhino.Pi*4 x = 2*r*(cos(theta)-.5*cos(2*(theta))) y = 2*r*(sin(theta)-.5*sin(2*(theta))) z = 0 arrPoints(n)=array(x,y,z) Next Rhino.AddCurve(arrPoints) End SubTags: geometry, graph drawing, Rhinoscript, sample script
Feb 15, 2009 0
Sunday Script | Sort Colors to Layers
Option Explicit
'Script written by ksteinfe
'Script copyrighted by nobody!
'Script version Wednesday, April 23, 2008 12:37:44 PM
Call Main()
Sub Main()
Dim arrObjects, strObject
arrObjects = Rhino.GetObjects("select objects")
Rhino.AddLayer("colorSort")
Rhino.EnableRedraw vbFalse
For Each strObject In arrObjects
Dim lngColor
lngColor = Rhino.ObjectColor(strObject)
If Not Rhino.IsLayer(lngColor) Then
Call Rhino.AddLayer(lngColor, lngColor, True, False, "colorSort")
End If
Call Rhino.ObjectLayer(strObject, lngColor)
Call Rhino.ObjectColorSource(strObject,0)
Next
Rhino.EnableRedraw vbTrue
End Sub
Tags: layer management, Rhinoscript, sample scriptFeb 9, 2009 Comments Off
Rhinoscript | Pseudocode Example
Here’s an example of how to write pseudocode from an existing piece of code.
The code
Sub randomPtsOnCrv()
Dim strObject, noOfPts, domain, i
strObject = Rhino.getObject(”select curves”, 4)
noOfPts = Rhino.getReal(”number of points”, 10)domain = Rhino.CurveDomain (strObject)
For i = 0 To noOfPts
Rhino.AddPoint Rhino.EvaluateCurve (strObject, (domain(1)*Rnd))
NextEnd Sub
The Pseudocode
No tags for this post.Create the following variables: strObject, noOfPts, domain, i
Ask the user to select a curve, and store the result inside “strObject”
(This curve will be the curve we plot points on)Ask the user for a decimal number, and store it inside “noOfPts”
(This number will be used to determine the number of points to plot on the curve)Find the domain of the user selected curve
(The domain of a curve is described as an array of two numbers)Loop i 0->noOfPts
add a point to the rhino document at a randomly determined parameter value within its domain.
there’s alot going on in this single line:
Rnd = a random number between 0->1
domain(1) = the high domain number for the selected curve
Rnd*domain(1) = a random number between 0->domain(1)
Rhino.EvaluateCurve() returns an array of three coords (a 3d point) at a given location along a curve
End Loop




