Want to keep learning?

This content is taken from the University of Michigan's online course, Design Computing: 3D Modeling in Rhinoceros with Python Rhinoscript. Join the course to learn more.

Skip to 0 minutes and 6 seconds This video’s titled Attractor Point. So one common way of manipulating geometry in a point list is to use something called an Attractor Point. And that’s simply a point that we create within the scene, and that we input. So here I’m inputting a point and saving it in the variable attractor point and then create my point list. And then loop through my point list. And the first thing I’m going to do is measure the distance between each point within that list as I go through the loop one at a time.

Skip to 0 minutes and 54 seconds And using a function which we haven’t seen before called rs Distance, and that simply measures the distance between two points in space. So whatever my current point is in my list to the attractor point, and I’m going to save it in the variable distance and then first I’m just going to print it out. So let’s run that.

Skip to 1 minute and 20 seconds So, select the attractor point creates my point, matrix C.

Skip to 1 minute and 28 seconds And then I can see my printout. And the numbers go from 11 point something down to one point something is the lowest.

Skip to 1 minute and 40 seconds And so what that’s doing is it’s measuring the distance from that point to every point within the matrix C. So if you can imagine a sort of line between all of these points and this list that’s printed out of the distances and makes a lot of sense because the points that I start with here, have a higher value because I might pointless starts its generation over here. So these points are going to have a higher value and then as I get closer to this point, my attractor point, those values are going to go down.

Skip to 2 minutes and 22 seconds So let’s do something with that, that distance generator.

Skip to 2 minutes and 29 seconds So I could use that to let’s say, create a circle, add a circle on each, using as its origin point, the current point within the list. And then, let’s just start with the sort of, raw distance value.

Skip to 2 minutes and 49 seconds And we’ll see what that generates.

Skip to 2 minutes and 59 seconds Okay, so it generates a pretty crazy pattern. But if we think about it, it starts to make a lot of sense my circles which are furthest from the attractor point or largest. So their radius, which is that value there and you can see it’s going to go back and intersect the attractor point because that radius value is that distance from that point to that point. So the circumference of that circle’s is always going to touch that attractor point.

Skip to 3 minutes and 38 seconds I can undo that. So if we wanted to lessen its effect like we did with the I value and the rotation, I could put a divider in here. So let’s divide it by, let’s say 20 to start with and we could also print out to see what those values are going to be.

Skip to 4 minutes and 11 seconds So now, I’m getting a matrix C of circles whose size diminishes as they get closer to the attractor point. And of course this is going to change if I relocate the attractor point, it’s going to have a different effect on the matrix C.

Skip to 4 minutes and 38 seconds So, attractor points are a very interesting system that we’ll continue to use in different ways throughout the rest of the course. One thing maybe to work on, to think about if you take the previous lesson which we copied the closed planar curve to the point and then we rotated them based on the eye. How could you use the distance instead to do a rotation? Or another thing might be a scale. How could you use the distance value that you’re measuring from the attractor point to the other points as a way to scale, maybe something besides a circle, that could be a really interesting exercise.

Skip to 5 minutes and 19 seconds And you’ll have to like with this, you’re going to have to probably divide the distance value or create some mathematics that get it in the range that are workable. But should be fairly straightforward and would be also a good thing to do for the next assignment.

attractor point

what’s in this video

In this video I demonstrate a common way of manipulating geometry using an attractor point. During the demonstration I introduce a function that we have not used before in the course—the rs.Distance function.

check your knowledge

[Pause the video and take a moment to practice using attractor points]

Use the attractor point system in the Nested Loop: 2D Point Matrix code to manipulate the rotational angle of the transformed geometry.

tutorial code

import rhinoscriptsyntax as rs

#create an empty list
ptList = []

#input a point to use as an attractor
attrPt = rs.GetObject('select an attractor point',rs.filter.point)

#incremental loop to generate points
for i in range(10):
    for j in range(10):
        #define x in terms of i
        #define y in terms of j
        x = i
        y = j
        z = 0
        #rs.AddTextDot((x,y,z), (x,y,z)) 
        #save point values in a list
#loop through point list and print out index number and values
for i in range(len(ptList)):
#    print i, ':', ptList[i]
#    rs.AddTextDot(i, ptList[i])
    #measure distance between attractor point and current point in the list
    distance = rs.Distance(ptList[i], attrPt)
    print distance/20
    #create circle using distance value as radius
    rs.AddCircle(ptList[i], distance/20)

Share this video:

This video is from the free online course:

Design Computing: 3D Modeling in Rhinoceros with Python Rhinoscript

University of Michigan

Get a taste of this course

Find out what this course is like by previewing some of the course steps before you join: