Monday, September 7, 2009

This script creates some random points and then draws lines to the next closest point. The result is a bit unexpected... the line zig zags all over the place.


import py2rhino as p2r
import random as rnd
#===============================================================================
# Parameters
#===============================================================================
num_points = 100
#===============================================================================
# Main Script
#===============================================================================
#create some random points
points = []
for i in range(num_points):
x = rnd.randint(-25, 25)
y = rnd.randint(-25, 25)
z = rnd.randint(0,200)
points.append((x,y,z))
p2r.obj.Sphere.create((x,y,z), 0.5)

#create a starting point
pt1= (0,0,0)

#draw a line from to the next closest point
for pt_num in range(num_points):
pt2_num = p2r.util.point.points_closest_point(points, pt1)
pt2 = points[pt2_num]
p2r.obj.Line.create(pt1, pt2)
points.remove(pt2)
pt1 = pt2

print "done"

No comments:

Post a Comment