import Rhino import rhinoscriptsyntax as rs import scriptcontext from System.Drawing import Color import random as rnd import time """-------------------------------------------------------- RHINOSCRIPT METHODS USING PYTHON One Time Search to find all points within specified radius The points found inside the specified radius get sampled for closest neighbor No Repeat Search Search Sample = 1 Million Points Search Radius = 500 Units Search Space = Cube (5000,5000,5000) --------------------------------------------------------""" def closestSearch(pts, point): #function to sample point based on a search radius first then search for the closest inside that list mimic the rtree pass basically but with brute force ptsinRange = []#dynamic list to store points found inside initial search for i in range(len(pts)): dist = rs.Distance(pts[i],point)#find the distance from each point to the query point if dist < 500: ptsinRange.append(pts[i])#if the distance is less than 500 append that point to the ptsinRange List cPointIndex = rs.PointArrayClosestPoint(ptsinRange,point)#search for the closest index from that list of points in range cPoint = ptsinRange[cPointIndex] #find the closest point in the in range list from the index found above if cPoint[0] == point[0] and cPoint[1] == point[1] and cPoint[2] == point[1]:#test against the closest neighbor being you print "IS THE SAME" return cPoint,ptsinRange #return the closest neighbor and the list of points in range def main(): point = [5000/2,5000/2,5000/2] intNumPts = 1000000#specify number of sample points pts = []#store the random points in an empty list for x in range(0,intNumPts): randomPt = [rnd.random()*5000,rnd.random()*5000,rnd.random()*5000] #randomly place each point inside the 5k x 5k x 5k cube pts.append(randomPt)#append each random point to the pts list timeStart = time.time()#Start timer data = closestSearch(pts, point)#call closestsearch function Pass query pt and list of points to search print "ClosestPoint = {}".format(data[0])#print the closest neighbor print "Number of Pts in Range = {}".format(len(data[1]))#print how many points were captures inside the search radius timeEnd = time.time()#stop the timer print "time taken: {}".format(timeEnd - timeStart)#print the amount of time the calculations took main() Update