def createHelix(origin, nCores, nFloors, rad, ped, park, ptH, hP, subD, ang, counter): helixPed = [] helixPark = [] helixPts = [] curves = g.DataTree[object]() pHelix = g.DataTree[rg.Point3d]() angRamp = 360 / nCores for j in range(nCores * nFloors): for i in range(subD + 1): #Variable data tetha = (((angRamp - (2 * ang)) / subD) * i) + ang + (angRamp * j) zVect = (hP * i / (nCores * (subD))) + (hP * j / nCores) #print "zVect: " + str(zVect) + " , " + "J: " + str(j) + " , " + "I: " + str(i) pt0 = rs.PointAdd(origin, (0, 0, zVect)) pt = rs.Polar(pt0, tetha, rad) ptPed = rs.Polar(pt0, tetha, rad - pedOff) #Pedestrian points ptPark = rs.Polar(pt0, tetha, rad - pedOff - parkOff) #Carpark points helixPts.append(pt) helixPed.append(ptPed) helixPark.append(ptPark) if j < 1: slope = slopeCalc(helixPts[0], helixPts[1]) #print slope curves.Add(rs.AddInterpCurve(helixPts), g.Kernel.Data.GH_Path(j // nCores)) if ptH: pHelix.AddRange(helixPts, g.Kernel.Data.GH_Path( counter, j)) #Points to calculate ramp srf if ped: cPedAux.Add(rs.AddInterpCurve(helixPed), g.Kernel.Data.GH_Path(counter, j // nCores)) pPed.AddRange(helixPed, g.Kernel.Data.GH_Path( counter, j)) #Points to calculate ramp srf if park: cParkAux.Add(rs.AddInterpCurve(helixPark), g.Kernel.Data.GH_Path(counter, j // nCores)) pPark.AddRange(helixPark, g.Kernel.Data.GH_Path( counter, j)) #Points to calculate park srf #Passing points calculated to an ordered Output pSect.AddRange(helixPts, g.Kernel.Data.GH_Path(counter, j)) #Points to calculate ramp srf #Reset the point list helixPts = [] helixPed = [] helixPark = [] return (curves, slope, cPedAux, cParkAux, pHelix)
def neuralGrow(poistion,angle,length,maxangledeviation,generation,maxgeneration): goal=rs.Polar(poistion,angle,length) rs.AddCone(goal,poistion,11-generation) angle1=angle+random.uniform(-maxangledeviation,-5) angle2=angle+random.uniform(5,maxangledeviation) if generation<maxgeneration: neuralGrow(goal,angle1,length,maxangledeviation,generation+1,maxgeneration) neuralGrow(goal,angle2,length,maxangledeviation,generation+1,maxgeneration)
def randomwalk(poistion, angle, length, maxangledeviation, amountsteps): # poistion=(0,0,0) # angle=90 # length=90 # maxangledeviation=30 # amountsteps=1000 for i in range(amountsteps): goal = rs.Polar(poistion, angle, length) rs.AddLine(poistion, goal) poistion = goal angle = angle + (random.uniform(-maxangledeviation, maxangledeviation))
def GenerateCrossSection(sectionPoints, radius, rotation, smooth, curve, samples, p, q): points = [] avoidRoundoff = 0.01 for angle in rs.frange(0.0, 360.0 + avoidRoundoff, 360.0 / sectionPoints): points.append(rs.Polar((0.0, 0.0, 0.0), angle, radius)) rotXform = rs.XformRotation2(rotation, (0, 0, 1), (0, 0, 0)) points = rs.PointArrayTransform(points, rotXform) t = curve.Domain[0] crossSections = [] curveCurvature = curve.CurvatureAt(t) crossSectionPlane = None if not curveCurvature: crvPoint = curve.PointAt(t) crvTangent = curve.TangentAt(t) crvPerp = (0, 0, 1) crvNormal = Rhino.Geometry.Vector3d.CrossProduct(crvTangent, crvPerp) crossSectionPlane = Rhino.Geometry.Plane(crvPoint, crvPerp, crvNormal) else: crvPoint = curve.PointAt(t) crvTangent = curve.TangentAt(t) crvPerp = curve.CurvatureAt(t) crvPerp.Unitize crvNormal = Rhino.Geometry.Vector3d.CrossProduct(crvTangent, crvPerp) crossSectionPlane = Rhino.Geometry.Plane(crvPoint, crvPerp, crvNormal) if crossSectionPlane: xform = rs.XformChangeBasis(crossSectionPlane, rs.WorldXYPlane()) sectionVerts = rs.PointArrayTransform(points, xform) if (smooth): # Degree 3 curve to smooth it sectionCurve = Rhino.Geometry.Curve.CreateControlPointCurve( sectionVerts, 3) else: # Degree 1 curve (polyline) sectionCurve = Rhino.Geometry.Curve.CreateControlPointCurve( sectionVerts, 1) crossSection = rs.coercecurve(sectionCurve) return crossSection
def createSupPt(origin, nCores, nFloors, rad1, rad2, hP, ang): for i in range((nCores * nFloors) + 1): ptO = rs.PointAdd(origin, (0, 0, hP * i / nCores)) pt1 = rs.Polar(ptO, (360 * i / nCores), rad1) pt1AuxA = rs.Polar(ptO, (360 * i / nCores) + ang, rad1) pt1AuxB = rs.Polar(ptO, (360 * i / nCores) - ang, rad1) pt2 = rs.Polar(ptO, (360 * i / nCores), rad2) pt2AuxA = rs.Polar(ptO, (360 * i / nCores) + ang, rad2) pt2AuxB = rs.Polar(ptO, (360 * i / nCores) - ang, rad2) #pExt.append(pt1) pExt.Add(pt1, g.Kernel.Data.GH_Path(i // nCores)) auxExtPts.extend([pt1AuxA, pt1AuxB]) arc1 = rs.AddArc3Pt(pt1AuxA, pt1AuxB, pt1) #arc drawing pedestrian path in core area arcPed.Add( rs.OffsetCurve(arc1, origin, pedOff)[0], g.Kernel.Data.GH_Path(i // nCores)) arcPark.Add( rs.OffsetCurve(arc1, origin, pedOff + parkOff)[0], g.Kernel.Data.GH_Path(i // nCores)) #extArcs.append(arc1) extArcs.Add(arc1, g.Kernel.Data.GH_Path(i // nCores)) #pInt.append(pt2) pInt.Add(pt2, g.Kernel.Data.GH_Path(i // nCores)) auxIntPts.extend([pt2AuxA, pt2AuxB]) arc2 = rs.AddArc3Pt(pt2AuxA, pt2AuxB, pt2) #intArcs.append(arc2) intArcs.Add(arc2, g.Kernel.Data.GH_Path(i // nCores)) pSupExt.AddRange([pt1AuxA, pt1AuxB, pt2AuxA, pt2AuxB], g.Kernel.Data.GH_Path(i // nCores))
def SampleGardenPath(): # Acquire information for the garden path start_point = rs.GetPoint('Start point of path') if start_point is None: return end_point = rs.GetPoint('End point of path', start_point) if end_point is None: return half_width = rs.GetDistance(start_point, None, 'First width point', 'Half width of path') if half_width is None: return tile_radius = rs.GetReal('Radius of tiles', 1.0) if tile_radius is None: return if tile_radius <= 0.0: return tile_spacing = rs.GetReal('Distance between tiles', 1.0) if tile_spacing is None: return if tile_spacing < 0.0: return # To increase speed, disable redrawing rs.EnableRedraw(False) # Calculate angles angle_rc = rs.Angle(start_point, end_point) angle = angle_rc[0] length = rs.Distance(start_point, end_point) width = half_width * 2 angle_p90 = angle + 90.0 angle_m90 = angle - 90.0 # Draw the outline of the path polyline = [] polyline.append(rs.Polar(start_point, angle_m90, half_width)) polyline.append(rs.Polar(polyline[0], angle, length)) polyline.append(rs.Polar(polyline[1], angle_p90, width)) polyline.append(rs.Polar(polyline[2], angle + 180.0, length)) polyline.append(polyline[0]) rs.AddPolyline(polyline) # Draw the rows of tiles plane = rs.WorldXYPlane() distance = tile_radius + tile_spacing offset = 0.0 while (distance <= length - tile_radius): # Place one row of tiles given polyline along path and possibly offset it first = rs.Polar(start_point, angle, distance) current = rs.Polar(first, angle_p90, offset) next = current while (rs.Distance(first, next) < half_width - tile_radius): plane = rs.MovePlane(plane, next) rs.AddCircle(plane, tile_radius) next = rs.Polar(next, angle_p90, tile_spacing + tile_radius + tile_radius) next = rs.Polar(current, angle_m90, tile_spacing + tile_radius + tile_radius) while (rs.Distance(first, next) < half_width - tile_radius): plane = rs.MovePlane(plane, next) rs.AddCircle(plane, tile_radius) next = rs.Polar(next, angle_m90, tile_spacing + tile_radius + tile_radius) distance = distance + ((tile_spacing + tile_radius + tile_radius) * math.sin(60.0 * 180.0 / math.pi)) if (offset == 0.0): offset = (tile_spacing + tile_radius + tile_radius) * math.cos( 60.0 * 180.0 / math.pi) else: offset = 0.0 rs.EnableRedraw(True)
def test(): #Assign variables to the sin and cos functions for use later. Sin = math.sin Cos = math.cos # Acquire information for the garden path # set default values for the distances default_hwidth = 1 default_trad = 1 default_tspace = 1 # look for any previously used values stored in sticky and use those if available. if sc.sticky.has_key("GP_WIDTH"): default_hwidth = sc.sticky["GP_WIDTH"] if sc.sticky.has_key("GP_RAD"): default_trad = sc.sticky["GP_RAD"] if sc.sticky.has_key("GP_Space"): default_tspace = sc.sticky["GP_SPACE"] #get the path direction, length and location from two points entered by the user sp = rs.GetPoint("Start point of path centerline") if sp is None: return ep = rs.GetPoint("End point of path centerline", sp) if ep is None: return #now ask the user what the distances should be, offering the defaults arrived at above hwidth = rs.GetDistance(sp, default_hwidth, second_pt_msg="Half width of path") if hwidth is None: return #Store the new value in sticky for use next time sc.sticky["GP_WIDTH"] = hwidth trad = rs.GetDistance(sp, default_trad, second_pt_msg="Radius of tiles") if trad is None: return #Store the new value in sticky for use next time sc.sticky["GP_RAD"] = trad tspace = rs.GetDistance(sp, default_tspace, second_pt_msg="Distance between tiles") if tspace is None: return #Store the new value in sticky for use next time sc.sticky["GP_SPACE"] = tspace # Calculate angles temp = rs.Angle(sp, ep) pangle = temp[0] plength = rs.Distance(sp, ep) width = hwidth * 2 angp90 = pangle + 90.0 angm90 = pangle - 90.0 # To increase speed, disable redrawing rs.EnableRedraw(False) # Draw the outline of the path #make an empty list pline = [] #add points to the list pline.append(rs.Polar(sp, angm90, hwidth)) pline.append(rs.Polar(pline[0], pangle, plength)) pline.append(rs.Polar(pline[1], angp90, width)) pline.append(rs.Polar(pline[2], pangle + 180.0, plength)) #add the first point back on to the end of the list to close the pline pline.append(pline[0]) #create the polyline from the lst of points. rs.AddPolyline(pline) # Draw the rows of tiles #define a plane - #using the WorldXY plane the reults will always be added parallel to that plane, #regardless of the active plane where the points are picked. plane = rs.WorldXYPlane() pdist = trad + tspace off = 0.0 while (pdist <= plength - trad): #Place one row of tiles given distance along path # and possibly offset it pfirst = rs.Polar(sp, pangle, pdist) pctile = rs.Polar(pfirst, angp90, off) pltile = pctile while (rs.Distance(pfirst, pltile) < hwidth - trad): plane = rs.MovePlane(plane, pltile) rs.AddCircle(plane, trad) pltile = rs.Polar(pltile, angp90, tspace + trad + trad) pltile = rs.Polar(pctile, angm90, tspace + trad + trad) while (rs.Distance(pfirst, pltile) < hwidth - trad): plane = rs.MovePlane(plane, pltile) rs.AddCircle(plane, trad) pltile = rs.Polar(pltile, angm90, tspace + trad + trad) pdist = pdist + ((tspace + trad + trad) * Sin(math.radians(60))) if off == 0.0: off = (tspace + trad + trad) * Cos(math.radians(60)) else: off = 0.0