 So that's everything in the vector 2 type. The vector 3 type of course has an extra z component It has a third float and so we have these two more static properties forward and back. Forward is the unit vector pointing down the z-axis in the positive direction and back is the unit vector pointing in the negative direction down the z-axis. Then vector 3 has several methods which vector 2 doesn't and I'm not sure why that's the case because I can imagine scenarios where you'd want to do these things on vector 2s as well. Though the fact that vector 2 doesn't have these methods isn't really a big hindrance because we can always just take our vector 2 values and get their vector 3 equivalent where it's the same values except of course the z component is zero and then use these methods to get our results and just convert back to a vector 2. So it's not much of a hindrance that vector 2 doesn't have these but it is still just a little strange. I'm not sure what the rationale for that was. Anyway, so the first of these ortho normalize has two overloads, one taking two vectors and one taking three and all these vector arguments are passed by reference. Ortho normalize doesn't return anything. It's modifying the vectors that you pass in and here looking at the first overload but it does to a the first argument is it simply normalizes it but then the second vector it wants to make that a unit vector that is perpendicular to a and of course given a vector there is a full 360 degrees of possible vectors that are perpendicular to it And so the question is well, which unit vector does B become? Well, what it does is it takes whatever the input vector B is and between A and B that forms a plane and you can imagine B being swung on that plane until it is perpendicular with A and that's what ortho normalize does. Given two vectors, we want to tweak them until they're unit vectors that are perpendicular to each other. A doesn't move, B is adjusted to be perpendicular to A. The second overload does the same thing but then for C the third vector argument ortho normalize will mutate this into a unit vector that's perpendicular to both A and B. So this is like adding in a third perpendicular axis adding in a unit vector that's perpendicular to both of those while there's two possible choices and Of course those two vectors go in opposite directions So the question is well, which of those two possibilities will ortho normalize choose and that is determined by for whatever your input vector is vectors A and B form a plane and C is either pointing to one side of that plane or the other and that determines which of the two unit vectors perpendicular to A and B that C will become and Actually, also this is the case where C is already on the plane of A and B So I don't know how it breaks the tie in that case That has to break it in one way or the other. So the algorithm probably just takes one of the two Next we have the project method and here you should think of the vector B as being more like a ray So it's describing a direction But imagine it not really having a magnitude it just goes off into infinity and The vector that project returns is the point along that ray that ray of B Which a is closest to a describes a point and somewhere along the ray of B. There's a point which a is closest to Another way to think of it is again imagine B is more like a ray going off into infinity But it forms the right triangle with a and project will return for that right triangle It returns the length of the vector along B that forms that right triangle It returns a so-called adjacent of that right triangle And then we have project on plane which does something very similar Except instead of projecting a onto the ray described by B. It projects a onto the line perpendicular to B So it's returning the point on that line perpendicular to B, which a is closest to The formula for this is actually very simple You simply project a onto B and subtract the result of that from a and that gets us the result of project on plane Here's a little illustration of the project method We have our vectors a and B and we're projecting a onto B and then we're going to draw a is green B is yellow and the projection vector will make black Come over here play the game Maximize this so here's our vector a in green our vector B in yellow And if we project a on to B There's a right triangle formed between them and when you form the right triangle between them This is where the so-called adjacent of that right triangle ends or another way to think of it the closest point on the line Described by B the closest point to vector a this point over here is this one right here with a black line ends And actually I really shouldn't have said that we project on to a ray of B It's always a line because as we can see here if we're to change a and make this Negative to come back here So now I imagine B is a line extending off in both directions into infinity And so the closest point here of a on that that line of B is right here In fact, just be clear It really doesn't matter what the magnitude of B is if we normalize this or just here I'm just going to divide it by some random number to make it much smaller if we do that come back Wait for the code to recompile doesn't change the projection whatsoever So the length of the B vector we're projecting up to its magnitude does not matter Now instead of project Let's use project on plane drawing a screen B is yellow and the projection vector as black. Let's see what that gets us Here's our a vector. Here's B And again the magnitude of B really doesn't matter all it's used for in this case is to describe a line running Perpendicular to it so it'd be a line running this way and what we want to find is the point along that line Which a is closest to and as you can see that's right here Though another way to think of it is that we're forming a right triangle And so the vector we get back for the method is actually the adjacent of that right triangle It's just in this case. It's a right triangle formed between a and the line perpendicular to B rather than B itself So that's both project and project on plane and just understand I've demonstrated them in two dimensions on the XY plane, but we can use any three-dimensional vectors So here, let me just quickly demonstrate that I will give this a z-core of four And we come back wait for the update for the code to recompile and well It doesn't seem to have changed But that's just because of our orthographic perspective if I switch out to perspective mode you can see here that now that vector is Going back into the z-distance and so what the method does is that for the plane formed by a and B It finds the line perpendicular to B on that plane and that is what is projecting a onto Next on vector 3 we have slurp and slurp unclamped These are much like lurp and lurp unclamped which we saw in vector 2 vector 3 has those as well But in addition it has these two slurp and slurp unclamped and the difference is that here We are spherically linearly interpolating rather than just linearly interpolating and what that means is that we are interpolating a position in between a and B we're going from a towards B in this case 40% of the way But instead of going directly It's as if we're moving along the surface of a sphere hence the name spherically linearly interpolating Except because a and B aren't necessarily the same magnitude I think it might be more accurate to think of this as a method that linearly interpolates the angle of movement From a to B rather than the absolute position of a and B. It's probably just easier to illustrate this in code So here we have our vectors a and B and we're going to draw the first one as a green line the second as a red And then we're going to draw three slurps from a to B first 25% of the way from a to B then 50% and then 75% And we'll make those blue and then we'll do the same thing with lurp But make those magenta and because both of these vectors just for simplicity of demonstration I made them both on the XY plane they both have Z components of zero When we go back to unity, I'm gonna want to fix my axis. So we're looking at the XY plane orthographic projection Expand this and then hit play Okay, so green. This is the a vector The red vector is B and then if we linearly interpolate between the position of a and B This is 25% of the way. This is 50% of the way. This is 75% of the way But when we spherically linearly interpolate This vector here is a vector where the full angle between a and B. This is 25% of that angle This is 50% of an angle and this is 75% of that angle And it turns out that well halfway our lurp and a slurp are going to have the same direction vectors But that's not the case at other points along the way from a to B And understand the magnitude of our slurp vectors the blue vectors here That is determined by linearly interpolating between the magnitude of a and B But in this case, I made their magnitudes the same So the magnitude isn't changing in this case. It really looks like a spherical linear interpolation It's as if we're moving along the the surface of a sphere or rather in two dimensions along the surface of a circle But if I come back here, I'm gonna make this shorter same direction just shorter divided everything by two Wait for the recompile and then okay. Yeah So the linear interpolation part that that makes sense. It's just the points again 25% 50% and 75% of the way from a to B But now our slurp vectors The angles haven't changed their directions are the same but the magnitude of these vectors this one is 25% in between the magnitude of a and B This is 50% in between the magnitude of a and B and this is 75% of the magnitude from a to B and just to illustrate again that This can work in three dimensions here I'll give this a z component of seven save that code go back here wait for the recompile and Now we actually get different results and that's actually apparent in the orthographic projection But here I'll switch to perspective view come here and rotate. So the way to think of it is that A and B form a plane and for slurp. We are linearly interpolating the angle between a and B So this first vector over here the angle between it and a is 25% of the angle between B and a and Again, the magnitude is linearly interpolated to be 25% of the way from a to B I believe in this case a would be a longer vector. Let me make that even more apparent I'll make this a big number and we'll just move over a little bit Wait for the recompile and yeah So now a is definitely bigger than B And so when we linearly interpolate 25% of the way from a to B The magnitude is actually being shrunk as we get closer to B As for slurp unclamped in that case our percentage value is not clamped into the range of zero to one So we can have like 1.25 1.5 1.75 etc And we'll draw these in black and let's see what that looks like here and There so this is 125% of the way from a to B. This is a hundred fifty hundred seventy five hundred two hundred percent 225 250 and notice in this case because a is longer than B The magnitude is getting shorter and shorter and in fact eventually our unclamped slurp vectors are going to go negative In fact, I can illustrate this if here. I'll just make this z component larger So now vector a is a significantly larger magnitude than B come back here wait for the code to be compile and okay Well, here's 1.25. Here's 1.5 And here's you expect the angle to be right here and it is but now our magnitude has gone negative So it's now going off into the other direction So just watch out for that. It can be a little confusing We have another method rotate towards which is like slurp But here the third argument is not a percentage of travel from a to B It's rather the amount we want to travel in terms of absolute radiance So we're still finding a vector that is swung from a to B But we're specifying in radiance the actual angular distance We want to go and in the event this angle is larger than the angle between a and B Well, what we get back is a vector with the same direction as B. It won't overshoot So in a sense the the rotation the movement is clamped by B itself And then this fourth argument is specifying how much we want the magnitude to change Like say here imagine a has a magnitude of 5 and B has a magnitude of 10 Well, the vector returned by rotate towards should have a magnitude closer to be how much closer Well two units closer So the returned vectors magnitude would be 7 in that case though if the difference in magnitude between a and B Were less than this distance the returned vector would just have the magnitude of B itself So it's possible we specify values large enough for both these arguments where the vector we get back is just equal to B And someone unfortunately the documentation says something about linearly interpolating the magnitude But in all my tests I didn't see that behavior at all It seems to always return a vector where this is the change in magnitude This is the delta magnitude, but it's capped at the magnitude of B So we're never going to overshoot B As far as I can tell that's the real behavior and there's no actual linear interpolation between the magnitude And so whatever the angle it is we specify that has no bearing on the magnitude of the return vector Only the last argument has an effect on that Lastly we have the cross method which gets us the cross product of two vectors And this is the one method that doesn't apply to vector twos It's something that doesn't make sense in two dimensions Because what it returns effectively is a vector that is perpendicular to both A and B And the way you compute that is that well for the x component That's found with these operations which note don't involve the x components of either A or B And then when you find the y components it's these operations which note don't involve the y components of A or B And then to find the z component similar deal except again it doesn't involve the z components of either A or B Anyway, we won't go through the proof here But this gets us back a vector which is perpendicular to both A and B And the question is well, which way does it go? Given two vectors the third vector that's perpendicular to them goes in one of two directions And so which way does it face? Well the way this is computed effectively gives us the the cross product according to the left-handed rule So if you hold up your left hand and form an L with your thumb And index finger and stick out your middle finger away from them It's like your hand is representing three perpendicular axes Well, your thumb would be the A vector your index finger would be B And your middle finger is the cross product If you made the same gesture with your right hand Where A is your thumb and B is your index finger your middle finger would in the sense be oriented in the opposite direction So that's the distinction between left hand and right hand systems So when we have three axes we talk about left-handed systems and right-handed systems Anyway, so that explains the direction, but what about the magnitude? Well, it turns out the magnitude of the cross product again We won't prove this but it turns out to be equal to the magnitude of A and B multiplied together With also the sign of the angle between them And like with the dot product this equation can come in useful in certain circumstances. We won't go into here Let's though just see a demonstration of getting the cross product Here we have A and B. I'm drawing A is green B is red And I'm competing the cross product manually And then drawing that as a yellow line But then I'm also competing the cross product using the built-in method and we should see the same result But I'm drawing that as a black line on top of our yellow line, but normalized so it should be much shorter Otherwise we wouldn't see the yellow line at all And lastly here I'm getting the cross product of this time B and A. I've reversed the order Because cross product unlike dot product is not commutative the order matters And what that changes is it flips the direction of the cross product vector The left hand rule still applies form three perpendicular axes in your left hand with your thumb index finger and middle finger But in this case now B is your thumb A is your index finger And so now the cross product is going in the other way than if we got the cross product of A and B So let's see this in unity There so we have our two original vectors A is green B is red Yellows that are cross product with the full magnitude But then if we normalize it we get this little black line And the cayenne line is the cross product of B and A also normalized And notice it's just the inverse direction from the cross product of A and B