The name of this video is Midpoint Function. So often we'll write functions as little tools that allow us to do one particular thing within the code. So this one allows us to or finds a midpoint value between any two input points, and the logic of it is fairly straight forward. So if I have, let's say, two points at five and 15 along the x-axis. The y-value and the z-value of value are negligible in this situation, so we don't need to calculate for those, but we would anyway. But they're going to end up being 0 because this is just along the x -xis. But if I am inputting five and 15 for x, so all I need to do is add those together to get 20 and then divide by 2. So that's the logic of our equation for finding a midpoint between any two points. So if we get rid of this, go back to our code. Let's run it for a second and then I'll go back and explain it. So select 0.1, select 0.2, and it's created that point between those two points. So how does this work? So I'm inputting those two points here, and then I'm calling this function called midpoint, and I'm feeding those two points to that function. It then goes up to that function, so it feeds those point values in and then I've set up a variable called point, and the reason I set it equal to none is that I want to just make sure that I'm clearing all data if there might be leftover data from running the function previously. So I just make sure that that's cleared, and point is a variable that since it's contained with this function, it's only operating within that function. Then lines 9 and 10 are where I create my calculation. Well, it's a little bit familiar to the translation calculation, although this is an addition and then a division. But breaking the point values out into their x, their y, and the z values is the same as I did within the translation, because a point value that I'm feeding in is a tuple of three values representing x, y, and z. So what I'm doing here is I'm just breaking them out and I'm taking the x's, adding them together like I just showed, and rhino space, and then dividing by 2, and then that makes my new x value for my midpoint. I do the same for y, and I do the same for z. Then I'm making those into their own list, and then I return that to whatever value is produced from that. I'm then going to return to the main function where the midpoint function was called. So that returns that, and then because I've set the call equal to a new variable here in the main, it's collecting whatever is being returned from that midpoint function. It's printing it out. So it prints it out down here, my value is 10, 0, 0. Then I render that out in the scene so I can see it. So if I run it again and we can move these points to anywhere within the scene and it's going to create that midpoint. So it's a really handy function because it will work anywhere in space. So we haven't gotten in the z yet, but it will work, if these points are anywhere up in space. I'm always going to be able to find that midpoint between those two points. So it's a very handy function. So let's just take a look at it in an example. So I took a previous code that we did from an earlier lesson. So this is the one in which I adapted the bone structure to the dictionary 2D point matrix, I'm doing a randomization here on the point matrix, and I've put that in a function called point matrix. So here I'm inputting my imax and jmax, this is just like I showed in the previous example, previous video. Calling that point matrix function from here and runs, produces my point grid and then loops through that again and then produces my geometry. Another one thing that I've done differently here is, if you remember, I had to find a midpoint of a line that I drew between two points in order to use it as a centroid. So instead of doing that, I've taken my midpoint function and I've just dropped it in here, made sure it's outside of the other functions. So it's a stand-alone thing, and at this point, within the point matrix code, I call up that function and I feed it two diagonally opposing points. So my i minus 1, j minus 1, and my ij are two diagonally opposed points. I'm going to find the midpoint between those two, and then I'm going to call that or save that in a variable centroid, which then gets utilized to create the geometry. So once we have these functions written, there are these self-contained little tools that allow us to do this function, or do this little operation from anywhere within the code. So this is a handy one that you'll probably use a bit because it also eliminates a couple lines of code. You can see too that are codes are starting to get longer and they get more complicated and have more parts to them. So if this was one long stream of code, it becomes difficult to work on it because it's not in these organized chunks, and I can collapse these two. So if I just wanted to, let's say work on the point matrix, I could just open that up and work on that and then collapse it when I'm done or work on this one. So its functions become a really handy way of organizing a larger, more complex code. So let's run this. We've seen this before, but it runs just fine. We'll take a look at one more function example next.