Option Explicit 'Script written by rwr 'Script is open source 'Script version Monday, August 31, 2009 12:58:23 PM '------------------------------------------------------------------------------ ' Purpose: Creates lines normal to the surface '------------------------------------------------------------------------------ Call Main() Sub Main() 'get surface object Dim strsrf : strsrf = rhino.getobject("select a surface to populate",8) If IsNull(strSrf) Then Exit Sub 'get divisions in u and v direction Dim uDiv : uDiv = Rhino.GetInteger("divisions in U direction", 10) Dim vDiv : vDiv = Rhino.GetInteger("divisions in V direction", 10) 'get offset height Dim height : height = Rhino.GetReal ("offset height",10) 'domain interval in u and v Dim uDomain : uDomain = Rhino.SurfaceDomain(strsrf,0) Dim vDomain : vDomain = Rhino.SurfaceDomain(strsrf,1) 'calculate interval step in u and v direction Dim ustep : ustep = uDomain(1)/uDiv Dim vstep : vstep = vDomain(1)/vDiv 'disable redraw to speed up the execution of the script Rhino.EnableRedraw False Dim u, v For u = 0 To uDomain(1) Step ustep For v = 0 To vDomain(1)+ vstep Step vstep Dim uvPoint, arrData, proPoint1, proPoint2 'call srfCurvature function to calculate point on surface uvPoint = Array (u,v) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is '0' proPoint1 = offsetCalc(arrData, 0) 'call srfCurvature function to calculate offset point uvPoint = Array (u,v) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint2 = offsetCalc(arrData, height) 'add a line normal to the surface Rhino.AddLine proPoint1, proPoint2 Next Next 'Enable Redraw Rhino.EnableRedraw True End Sub 'surface curvature function by rr Function srfCurvature (strsrf, uvPoint) Dim arrPoint, arrParam 'evaluate point arrPoint = Rhino.EvaluateSurface (strsrf, uvPoint) 'returns the UV parameter of the point on the surface that is closest to the current uv step arrParam = Rhino.SurfaceClosestPoint(strsrf, arrPoint) If IsArray(arrParam) Then 'returns the curvature of a surface at a U,V parameter srfCurvature = Rhino.SurfaceCurvature(strsrf, arrParam) If IsArray(srfCurvature) Then End If End If End Function 'offset calc function Function offsetCalc(arrData, height) Dim vscaled vscaled = VectorScale(arrData(1),height) offsetCalc = VectorAdd(vscaled,arrData(0)) End Function 'function by RMA, "vectors.rvb" Function VectorAdd(v1, v2) VectorAdd = Null If Not IsArray(v1) Or (UBound(v1) <> 2) Then Exit Function If Not IsArray(v2) Or (UBound(v2) <> 2) Then Exit Function VectorAdd = Array(v1(0) + v2(0), v1(1) + v2(1), v1(2) + v2(2)) End Function 'function by RMA, "vectors.rvb" Function VectorScale(v, d) VectorScale = Null If Not IsArray(v) Or (UBound(v) <> 2) Then Exit Function If Not IsNumeric(d) Then Exit Function VectorScale = Array(v(0) * d, v(1) * d, v(2) * d) End Function