Intro to Python Scripting: 12 Vector Transformation

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

In this tutorial we take a look at vectors and how to create simple object transformations using them. Specifically, we creat some vectors to translate the position of a point and copy it to a new location using the CopyObject() method. We thing create a polyline though the list of translated and copied points. We use a couple of list methods from the Strings and Lists Tutorial, so be sure you check that out before going into this one. This is sort of an intro to a simple growth algorithm, it's not very logical growth, but it is growth.

#Transformations
 
import rhinoscriptsyntax as rs
import random
 
#ask user to create a point
userPt = rs.GetPoint("create a point")
pt = rs.AddPoint(userPt)
 
#create a list of points and append pt to the list
pts = []
pts.append(pt)
 
for i in range(0,100):
    xDir = random.uniform(-10.0, 10.0)
    yDir = random.uniform(-10.0, 10.0)
    zDir = 0.0
    vect = (xDir, yDir, zDir)
    newPt = rs.CopyObject(pts[-1],vect)
    pts.append(newPt)
 
myPolyline = rs.AddPolyline(pts)

Rating

Please rate this tutorial below. Thanks.

5
Average: 5 (7 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.

:)