Note: Because this is an ongoing series, viewers will not receive a certificate of completion.
Skill Level Intermediate
- [Narrator] I have my exercise file already. So, the standard off setting, in Rhino and in Grasshopper, the offset curve command, is a powerful tool, because it lets you offset complex nerbs curves, and it calculates precise offsets for these potentially complicated pieces of geometry. But if you're offsetting polygons, like this, you really don't need all of that horsepower in the component. You can see this is taking 21 milliseconds to compute, which is not a lot of time but, if you had a lot of curves it would make a difference. So, as an alternative, we have the offset loose component, which does a similar offset, but it takes a lot less computation to actually calculate the offest curve, because all it's doing is it's offsetting at the control points. So, if I were offsetting a complex nerbs curve here, that offset wouldn't be consistent along the entire length of the curve, it would really just be doing the offsets at the control points. But for polygons, that works great. So this is going to be a much more efficient way to offset a polygon, within Grasshopper, than using the standard offsetting tool. But what's actually happening inside of this offset? What if you want to break into it, and actually control these distances more discreetly? Cause, really what's happening is, this point, the vertex is being moved off of one edge, and off of the other edge; and so vectors are being calculated for this movement. And we can build a really simple script, that does the same offsetting process, but gives you access to the entire process, let's you see what's happening. And lets you apply this type of offsetting to other geometries. Like just points, or perhaps a mesh, vertices, kind of breaks the offsetting process down. So let's see how we build that. So for each of these polygons, I have a list of points, so first thing I want to do is get that list of points in the polygon, and I can use discontinuity to get the point in the polygon. Or I can use control points. See if I use discontinuity, I have four points for each polygon. And if I use control points, I have 5 points for each polygon. So, I'm going to use the discontinuities, we'll see in a second why that's a little bit easier. If I go to sets now, what I want to do is I want to get the angle at each of these node points. So to get that angle, I want to compare the edge, with it's adjacent edge as vectors. So, I'll go to sets, shift list, so I'm going to shift the list twice. First I'm going to shift it forward, and then here, I'm going to shift it back. So what that does is, it allows me to create vectors. So if I go to vector, vectors going to start at the discontinuity, and then go to the shifted list. So, each of these vectors is starting at a point, and then going to an adjacent point, but in two different directions. And I can visualize that, if we go to display, get the point, the vector, let me just turn the rest of this stuff off, so we can see clearly what we're doing here. So these vectors are going one direction, these vectors are going in the opposite direction. So that gives me the two vectors I need to make the comparison to find the angle. So now, I'll go to vector, vector, and I want angle. Right here. I'll compute the angle between these two vectors. Now what's important here, I'm working on the work plane. So, if you're operating in some other plane, you definitely want to use this plane input to set the plane they're using to solve this angle. The other thing to check here, so if this angle is smaller than the reflex angle, you may have something weird going on with the relationship between the plane that you're operating in, and the vectors that you're solving. Can see here that these angles are smaller, which makes sense because in a polygon, it's typical that the inside angles are going to be smaller than the outside angles. Reflex angle is the outside angle between the two vectors. So now, how do I use this angle to actually calculate that offset? Well if we think about what offsetting is doing, so let me just, I'm going to offset to the inside to make this clearer. When I'm finding this offset point, really what I want to know, I have this vector, this edge vector, and the question is, how far along this edge vector do I need to go to get to the place where this offset line intersects with that edge? Alright, so I'm going to move this vertex at the very corner of the polygon, in along this vector to here, and then I'm going to move it from here, across to here, its final resting place. And I know how far I want the offset, which is this distance, so really, I'm creating a triangle. If I draw this out, I'm creating a triangle, like this. Where I know this distance, but I need to find this distance. So I'm just going to use a little trick, and I can use the sin equation so as the sin of this angle is going to be this distance over this distance. So, if I go to math, sin, what I want to do is I'll take the value that I'm offsetting, so we're going to set it to 1, and we're going to divide that by the sin, this is going to be the sin of the angle, and then I'm going to go to math, divide, then divide 1 by the sin curve. And now, I want to set the length of these vectors to this value. So vector, vector amplitude. I'm going to connect the vector, set its amplitude, connect my other vector, set it's amplitude, and now I need to use these two vectors, to move the points for my polygon. So, simplest way to do that is to go to transform, move, I'll plug in my points, I'll plug in the first vector, You can see it's moving along that vector. Now, I'm going to plug in my second vector. So they're being transformed in both ways, and now you see the point is landing right on that offset. And then I can go to curve and just rebuild that polygon. So, you could say this is just the hard way of doing something super simple. But I find they use this all the time. Because, sometimes you want to control each of these vectors individually. Which, in this process, is really easy. So, let's say I want to have two different offsets. This gives me that level of control. So now, I'm creating an offset that's kind of twisted from the original shape. And what I found is, most of my development within Grasshopper is in the service of creating real things, things that are going to be fabricated. And the small offsets for material thickness, or for tolerance become critical, and it often becomes important to have really precise over exactly how these offsets are happening, and sometimes those offsets are going to be three dimensional offsets, and not just curves in a plane. So this little offsetting script, this little logic, which replaces that loose offset, becomes really useful, because it opens up that offsetting process, and gives you really precise control. And, if you're using it all the time, you can just cluster it up, and that gives you a tool, you're own sort of custom offsetting tool that you can use anytime you would otherwise go for that loose offset.