{"id":1476,"date":"2012-12-11T14:43:38","date_gmt":"2012-12-11T14:43:38","guid":{"rendered":"http:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/?page_id=1476"},"modified":"2012-12-19T01:02:27","modified_gmt":"2012-12-19T01:02:27","slug":"code-4-add-title","status":"publish","type":"page","link":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/code\/code-4-add-title\/","title":{"rendered":"no &#8216;heimat&#8217; for you"},"content":{"rendered":"<p>&#8220;&#8221;&#8221;<br \/>\n##########################################################<br \/>\nscript written by matthew miller, pablo costa &amp; ezio blasetti<br \/>\nscript version Dec. 4, 2012<br \/>\n#########################################################<br \/>\n&#8220;&#8221;&#8221;<\/p>\n<p>import rhinoscriptsyntax as rs<br \/>\nimport random<\/p>\n<p>class dlaPt():<\/p>\n<p>def __init__(self, POS, GUID):<br \/>\nself.pos = POS<br \/>\nself.id = GUID<br \/>\nself.fertile = True<\/p>\n<p>def aggregate(self, howMany, howFar, otherDlaPts, attractors, percentBack, minLength):<br \/>\nif self.fertile:<br \/>\nnewDlaPts = []<br \/>\nfor i in range(howMany):<br \/>\ncrvPts = []<br \/>\ncrvPts.append(self.pos)<br \/>\n#randomize<br \/>\nx = random.random()-0.5<br \/>\ny = random.random()-0.5<br \/>\nz = random.random()-0.5<br \/>\n#make the random vector<br \/>\nvec = rs.VectorUnitize([x,y,z])<br \/>\nrnd = random.random()<br \/>\n#adjust it to the attractors<br \/>\nadjValue = self.attractor(self.pos, attractors, howFar+2)<br \/>\n#scale it to how far<br \/>\nvec = rs.VectorScale(vec, howFar*adjValue)<br \/>\n#add it to the coordinate of your pos<br \/>\nnewPos = rs.PointAdd(self.pos,vec)<br \/>\ncrvPts.append(newPos)<br \/>\n#randomize again<br \/>\nx2 = random.uniform(-rs.VectorLength(vec)\/6,rs.VectorLength(vec)\/6)<br \/>\ny2 = random.uniform(-rs.VectorLength(vec)\/6,rs.VectorLength(vec)\/3)<br \/>\nz2 = random.uniform(-rs.VectorLength(vec)\/6,rs.VectorLength(vec)\/3)<br \/>\nnewPos4Crv = rs.PointAdd(newPos,[x2,y2,z2])<\/p>\n<p>crvPts.append(newPos4Crv)<br \/>\n#make the point in rhino<br \/>\nnewID = rs.AddPoint(newPos)<br \/>\n#make a line between you and the new random point<br \/>\nif rs.VectorLength (vec) &gt; minLength:<br \/>\ncrv = rs.AddCurve(crvPts)<br \/>\n#find the closest other point in the aggregation<br \/>\ndomain = rs.CurveDomain(crv)<br \/>\nsubstr = domain[1]-domain[0]<br \/>\nuni = random.uniform(0,substr)<br \/>\nt = domain[0]+uni<br \/>\nbackPos = rs.EvaluateCurve(crv,t)<br \/>\nbackID = rs.AddPoint(backPos)<br \/>\notherPtCoords = []<br \/>\nfor otherPt in otherDlaPts:<br \/>\nif otherPt.pos != self.pos:<br \/>\notherPtCoords.append(otherPt.pos)<br \/>\nindex = rs.PointArrayClosestPoint(otherPtCoords, backPos)<br \/>\n#caclulate the distance between the new point and the closest other point<br \/>\ndistance = rs.Distance(backPos, otherPtCoords[index])<br \/>\nif distance &lt; howFar :<br \/>\npts4OtherCrv = []<br \/>\npts4OtherCrv.append(backPos)<br \/>\n#randomize again<br \/>\nx3 = random.uniform(-howFar\/6,howFar\/6)<br \/>\ny3 = random.uniform(-howFar\/6,howFar\/6)<br \/>\nz3 = random.uniform(-howFar\/6,howFar\/6)<br \/>\npts4OtherCrv.append(rs.PointAdd(backPos,[x3,y3,z3]))<br \/>\npts4OtherCrv.append(otherPtCoords[index])<br \/>\nrs.AddCurve(pts4OtherCrv)<br \/>\nrs.DeleteObject(newID)<br \/>\nnewDlaPts.append( dlaPt (backPos , backID) )<br \/>\nself.fertile = False<br \/>\nreturn newDlaPts<br \/>\nelse:<br \/>\nreturn &#8220;empty&#8221;<\/p>\n<p>def attractor(self, endPt, attrs, thres):<br \/>\n# Define a new array of Attractors&#8217; Coordinates from the Attractors&#8217; Identifiers<br \/>\nattrCoords = attrs<br \/>\n# Calculate the closest Attractor to the Test Point<br \/>\nclosestAttrIndex = rs.PointArrayClosestPoint(attrCoords, endPt)<br \/>\nclosestAttr = attrCoords[closestAttrIndex]<br \/>\n# Calculate the Distance between the Test Point and its closest Attractor<br \/>\ndist = rs.Distance(endPt, closestAttr)<br \/>\n# Calculate the Adjustment Amount:<br \/>\n# If the Distance is less than the Threshold Then<br \/>\nif dist&lt;thres:<br \/>\n#The Adjustment Amount will be 1 &#8211; ( ( Threshold &#8211; Distance ) \/ Threshold )<br \/>\nreturn 1-((thres-dist)\/thres)<br \/>\n#Else<br \/>\nelse:<br \/>\n#The Adjustment Amount will be 1<br \/>\nreturn 1<br \/>\n# End If<br \/>\n# End Function<\/p>\n<p>def Main():<\/p>\n<p>#get some points to make the lda starting points<br \/>\nptGUIDs = rs.GetObjects(&#8220;select some points&#8221;, rs.filter.point)<br \/>\nattractorGUIDs = rs.GetObjects(&#8220;select the attractors&#8221;, rs.filter.point)<br \/>\npercentBack = rs.GetReal(&#8220;how much back in percent 0-1&#8221;, 0.2,0,1)<br \/>\nminLength = rs.GetReal(&#8220;minimum length for curves&#8221;, 0.2)<br \/>\nattractors = []<br \/>\nfor attrGUID in attractorGUIDs:<br \/>\nattractors.append(rs.PointCoordinates(attrGUID))<br \/>\nmyDlaPts = []<br \/>\nfor ptGUID in ptGUIDs:<br \/>\ncoord = rs.PointCoordinates(ptGUID)<br \/>\nindex = rs.PointArrayClosestPoint(attractors,coord)<br \/>\ndist = rs.Distance(coord, attractors[index])<br \/>\nmyDlaPts.append( dlaPt(coord, ptGUID) )<\/p>\n<p>for i in range(5):<br \/>\nnewDlaPts = []<br \/>\nfor myDlaPt in myDlaPts:<br \/>\n#default recursive amount, default length<br \/>\ntempList = myDlaPt.aggregate(2, 15, myDlaPts, attractors, percentBack, minLength)<\/p>\n<p>if tempList != &#8220;empty&#8221;:<br \/>\nnewDlaPts.extend( tempList )<br \/>\nmyDlaPts.extend(newDlaPts)<\/p>\n<p>Main()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;&#8221;&#8221; ########################################################## script written by matthew miller, pablo costa &amp; ezio blasetti script version Dec. 4, 2012 ######################################################### &#8220;&#8221;&#8221; import rhinoscriptsyntax as rs import random class dlaPt(): def __init__(self, POS, GUID): self.pos = POS self.id = GUID self.fertile = True def aggregate(self, howMany, howFar, otherDlaPts, attractors, percentBack, minLength): if self.fertile: newDlaPts = [] for i [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":9,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-1476","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/comments?post=1476"}],"version-history":[{"count":6,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1476\/revisions"}],"predecessor-version":[{"id":1737,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1476\/revisions\/1737"}],"up":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/media?parent=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}