Intro to Python Scripting: 17 Simple Growth 01

Software: 
Tag: 
Video Duration: 
15 minutes
Author: 
Zach Downey

In this tutorial we will be taking a look at a simple growth algorithm. We begin with a starting point and then create a random point within a specific range. we then find a vector from the first point and the newly created point. We take that vector and unitize it and create a new vector that is the result of the original vector minus the unitized version of the vector. This new vector becomes our translation vector which we use to move the last point within 1 unit of the closest point in our set of points. We then add this new point to the points to search from and begin the process over again. Whew! That sounds complicated but it's really not. I created a few diagrams that hopefully help explain it a bit better, and I walk through them before we do any code so that we know where to begin.

import rhinoscriptsyntax as rs
import random
 
def placePt(x_range,y_range,z_range):
    x = random.uniform(0,x_range)
    y = random.uniform(0,y_range)
    z = random.uniform(0,z_range)
    pt = [x,y,z]
    return pt
 
 
 
ptZero = [50,50,0]
pts = []
pts.append(ptZero)
circleZero = rs.AddCircle(ptZero,0.5)
 
for i in range(0,100):
    pt = rs.AddPoint(placePt(100,100,0))
    index = rs.PointArrayClosestPoint(pts,pt)
    cp = pts[index]
    vect = rs.VectorCreate(cp,pt)
    unitVect = rs.VectorUnitize(vect)
    subVect = vect - unitVect
    newPt = rs.MoveObject(pt,subVect)
    rs.AddCircle(newPt,0.5)
    pts.append(newPt)

Rating

Please rate this tutorial below. Thanks.

5
Average: 4.7 (12 votes)

Want to Contribute?

Want to be an author? Drop us a line here we'd love to have you.

Already have a video you'd like to post? Send us a link and we'll get you going.

:)