## Agents Steered by a Vector Field – Example 11.1

One very much talked about method for contemporary form making proposes uses “Agent” behavior to structure designs, although successful applications of this seem few and far between, especially in “built” projects. Agents are, to generalize, anything that moves in the environment, and changes its behavior, or movement, based on things happening in the environment. Agents can be inorganic (water molecules) or organic; dumb (bacteria, termites), or smart (humans…sometimes..).  Sorry if I offended any termites. I’ll talk more about this later, but human behavior, while somewhat unpredictable on the individual scale, tends to become “dumb” (in other words predictable) on the large scale. Just think of the comments that predictably, come after any article of a political bent on the internet.

To model an agent, we will use a recursive loop, very similar to what we did with the growing lines examples in the previous group of examples. Strictly speaking, these are also “Agent” models since the lines grow and change their behavior, in part based on internal rules, and in part based on their environment. In these examples, though, after each step the vector or direction of movement will be reassessed at each step, and will steer the agent through the environment. For later examples, this steering will come partly in interaction with other agents (swarm behavior), but for now, we will use vector fields (Unit 6) to steer our agents, since we want to start slow. In some ways the results, especially of this first example, will look an awful lot like the results of the Grasshopper vector field tools (Unit 7) which we have already looked at, but will quickly move beyond that. To get agent based behavior to work right, you need a good grasp of data structuring. Pay attention to those flattens and grafts!

Step One – Set up Vector Field

The first step will be to go back to Example 6.3 and to set up a vector field. You can use other logics to create your vector field, and in the next example we will look at the field we created in Example 6.5, but for now this one is as good as any. You don’t have to create every step in Example 6.3 again, but you need at least the vectors and the anchor points for the vectors before the next step.

Step Two- Set up the Start Points for your “Field Lines”

Here we are using a random population for our starting points. You could use any points, theoretically, ones you draw, or even the starting points of the vectors from the overall field. Basically, at each one of these points a line will start to be drawn, and it will move based on the influence of the nearest vector.

Step Three – Set the Initial Vector

Before we enter the loop in the next step, we need to assign a vector to each of the points we generated in the last step. In this example, I find the nearest anchor point of the vector Field (from step one) to the start points from Step 2. I do this using the “Closest Point” component. Before you do this, “Flatten” both the Vectors generated in Step 1 as well as the “Anchor Points”. Only flatten them just before inputing them into the simulation right now. You will notice “Closest Point” will identify the closest point with an “index” number (the second output). We can use this index now with a “List Item” component to call out the vector associated with this particular point. We will assign this vector to the starting point of our field, and will move this point a small increment (which can be changed later) to get the line started.

Step Four – Insert New Point into List after starting points

A simple step, but you need to make sure your grafts are right. Basically, we will be creating a separate list of points, associated with each starting point, and these will be used to generate curves in a later step. I am grafting point the starting points (Red) and the points after the first movement (Green) and using an list “Insert” component to put the moved points in index position (1)

Step Five – Start the Loop

Now that we have our list started, we put this into a Loop using Anemone. If you have been following the previous examples this should be easy, but refer to example 8.1 if you have been skipping ahead >:-/

We will be doing something very similar to the last step, but in addition to finding the nearest vector to “steer” our agent, we are also going to take into account his “inertia” (that is, his current vector) as well. To get the current vector we simply list the last two points in our point list (there are only 2 points in the first round, but we will get more soon). We then use “Vector 2pt” to quantify this vector. We get the steering vector in the exact same way as in step 3.

Later we will look at an example where we can give more or less weight to the inertia vis a vis the closest steering vector, but for now, they have equal weight and the two are simply added together with an “Addition” component. Note that we use the “Vector Length” of the steering vectors (multiplied by our growth increment factor), to reset the amplitude of our summed vectors. This will make some of the lines grow faster than the others.

We use this new vector to move the last item in our list of points.

Step Six – Insert New Points into Ongoing List

The last steps in the loop are to insert the items into the ongoing tally, similar to step Four, but using a simple addition formula based on the loop “counter” to determine the insert position (Round + 2) will get the items from round 0 into position 2. This list then gets looped back in data channel 0.

After the loop, I already started using the “Nurbs” curve component to draw a curve based on my list of points. I trim the curves once they leave the playing field.

So that is about it! Not too hard, now, is it. Later once we start with Agent=>Agent behavior, the vectors associated with the closest points will change as these points will be moving and their own vectors will be changing, but the principles remain the same!

Variations

Theres not much too these variations. Just played around with the initial field parameters (See Example 6.3 again!) Each one of these runs only about 30 rounds. With a less dense field of starting points, you will need to let it run longer. The results look a lot like the examples from Unit 7, which was much easier, but now you should understand the logic better, and also be able to control it better as well.

Download the definition

Advertisements