Math for Game Devs [2022, part 10] • Abstract Algebra, Procedural Animation & Splines

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign what's that it's going I don't know what he wants all right he probably wants me to sit next to him while he's eating okay we are not officially starting yet I think we have five minutes left until the until the official start time I couldn't set the stream to 20 Past it had to be 15 best but um you know that's okay so I'm gonna hang out for a bit okay this segment is going to be weird um because I'm going to talk about a few things I've never talked about before during my math class and I'm not fully confident that I'm gonna be able to talk about it um we'll we'll see how it goes I guess um it's going to be a bit of an improv I guess most of mine are improv but at least I've talked about the previous things before um blip really just wanted to tell you here my personal hearing a role model the on the links a little bit terrifying but also also very nice of you to say I'm happy I'm able to inspire you somehow they will keep her okay where where are you going yeah that's the camera up there okay don't don't tip the entire microphone where are the three months you know I don't know how emotes work on YouTube I never looked into it yet I usually don't stream on YouTube so we'll eat that I think the camera is picking up the wrong thing you're supposed to focus on the cat there we go they're reading on time starting soon starting in two minutes I'm okay okay where where are you going what what's your plan Lee that's not your butt you wanna be in my left Thor don't show your butt to stream but that's inappropriate yeah that's inappropriate I will keep that my monkey Bistro okay let's see if we have some students all right please react if the students are here then then do react and show your presence door is also here he's showing his presence all the time right now okay okay hey you need to start my math class yeah you need to start the math class three what's your what's your plan buddy yeah I need to do math yeah that's that's the pop filter boy okay this is the stream now thanks though can I start my math class don't worry you're slobbering all over my microphone yeah think of the student star you're delaying what are they gonna think when you're you're holding me up like this which breed with Thor again oh Thor is not of any specific breed um we we or Ashley got Thor from a shelter and so he's a he's just a regular old mixed cat just a little guy this is true that that is sorry yeah he's long-haired tuxedo cat uh he's also American so he moved all the way from Seattle to Sweden that's this boy okay do you have a plan are you settling here okay all right there we go did it oh you did okay now we're ready to start um okay all right hmm we got our Photoshop just gotta check that outgoing Unity okay cool um I think we're ready ready to start everyone's present sorry for the thought thorough Interruption but you know you know the law you can't you can't move cats they have to move on their own um okay so this is our bonus session so this is where you're you can I I imagine we can just talk about whatever you want to talk about so if you have a question about things that are probably not related to what we're talking about that's fine it's okay to go in a bit of a tangent because this is kind of all just bonus optional content I guess um um I think the of the topics that we listed um it was either a procedural animation and easing functions and splines and more abstract algebra those were the three things um I think the um procedural animation uh I think is probably the most useful part of this in splines so I think we should start with the easing functions and then we go can go to the more abstract algebra later um I think that's good just to make sure that we have time to uh cover the more the more important things first um so the again abstract algebra and whatnot is is less useful in Game Dev it has a context and it has a use but it's more rare so I think we should start with easing functions and procedural animation um yeah all right and so um I think we should start with something that needs procedural animation we're going to start with something that looks bad and then we're going to make it look good I think that's the that's the starting point um and so we're gonna make a a new new script um we're gonna call this grid Cube all right okay uh so we have our grid Cube and it is somewhere uh it doesn't even have a cube that is that is very rude um so so let's let's give it a um let's just create a cube as a child object okay and let's switch to 2D I think that makes it makes it a little bit easier to you to see um wait using middle finger for scrolling seems illegal wait why is that illegal wait what do you use for scrolling is there is there a different option and just gonna create a material that's a little bit easier to see because now it's kind of hard to see um index finger what what why would you use your index finger um you guys don't no I think you might be alone in this um as we've just discovered um I mean I think I I don't use my uh ring finger to right click I usually swap with my middle finger between these two because very rare that I use them at the same time uh so too late to ask about the lecture before lunch uh I maybe I don't know what do you what do you want to ask try it see what happens okay I was just setting up this little grid Cube thing um I'm gonna call this Cube I'm gonna modify this script probably tried it on this off stream uh foreign so uh I was thinking we would start with a script that just moves a uh moves a character in this case it's just a cube uh moves the character based on uh input from the keyboard so we're gonna make our our old old trusty update Loop um why is it so dark even though material my material is a bright yellow um so if you want to make it very visible uh create a new material and set the material to or the Shader to unlit color um unlit color makes it so that you you don't have to then it's going to be the color you set it to um and then you might also be able to just toggle off Lighting in the scene and then in the in the scene View um and then I think it'll also look better [Music] um okay um so now we're just gonna make it make it very very basic movement code um so we're gonna have a some key that you press and then you then you need to move in some Direction um right and so we're gonna do transform dot position or rather if you press the key um right there um so get key down if you press this key we want to move the transform in the direction of the direction here and then we just then we just add all of our keys basically so um you can call this check move Echo I need I need me to drink okay so checkmu um keycode.w then we want to move in um vector2 dot up duplicate that and then we have S and then we want vector2 down a vector2 DOT left D is negative two dot right all right um now we have an extremely basic movement system right we press the key and then we move in that direction we just immediately snap to that position um okay let's let's recompile and now if we hit play um wait uh right we set it to equals we should do relative so we should do plus equals and I should also disable the uh turret because it's kind of distracting all right there we go so now I can press keys to to move this box this is like the the hello world of player and character movements um okay but but this looks kind of it's Snappy and responsive uh but that's kind of all it is it doesn't look very smooth it is very kind of basic right um and so what if you want to add smoothing to this and what if you want to add a custom smoothing to this instead of just having a like a snap movement or in or just like a lerp smoothing or whatever now we talked about that earlier uh that's the kind of smoothing where you're exponentially approaching some value or asymptotically asymptotically I forget I don't know how to pronounce it um and so you kind of approach your target with this like infinite falloff um but there are other ways that we can do this type of uh smoothing uh so that's uh that is kind of kind of a whole universe of uh of a topic um which is all about something called easing functions and so that's what we're going to look into now and so first off we want to make this movement be smooth uh we want this to be or rather we want it to be continuous because now it's completely discontinuous in just one frame we just jump to a new position and then we're there but what if we want to animate from point A to point B um so let's do that so so let's make a um we can make a Bool for is animating uh we need a vector three for the Target position and a vector three for start position um or maybe position start position Target all right uh so we're gonna we're gonna set up some State here um so so if we are um if we're not animating then we're going to check for input um so we can just scoot that over to a function right and then we have our enemy function um and we can also flip this okay um all right so we're also going to need to know when we started moving um actually we don't super need that value um we can call it move time I think that's that's good enough um all right uh and so in our animate function this is where we want to animate from the start position to the end position so what's going to happen is that when we press a key uh we are instead of just setting the position directly uh we're gonna do we're gonna set the start position of our movements we're going to set that to transform dot position and then the end position um or the target position is going to be position start plus our Direction and then we're going to set is animating to true so now we're going to start an animation so pressing a key will set these parameters and start the animation um okay and then we're also going to have to set move time to zero this is the time we've spent moving um okay so in our animate function uh first we're going to have to increment the time we've spent moving so we're going to do move time plus equals time dot Delta time so animate is going to be called every frame um we might want a different name for this uh what do we call this one this should be um animation time that's better and these are all going to be private things we don't have to expose those these are just um this is just for state right um and so we can make a header all right actually that's not even visible so I don't know why you're making a header um there we go that's a heading right and now we want to make the smooth interpolation from the start points and the end points and as you know we can use vector3.lurp to interpolate from point A to point B right in this case we want to interpolate from the start position to the Target position and then the T value is going to be the percentage from start to finish right and here's where it gets a little bit trickier because now um we only have time since the animation started but we need a t value and that depends on how long we want it to take to to make a single move like I make a move a single grid unit right um and so so maybe uh we want a public variable for that and that one we're going to call move time that's how long it takes to make a single single move um all right so how long do we want that to be maybe maybe we can make it um in the beginning we can start with one second I suppose um all right so now that we have the animation time the the time we've spent animating uh we can convert from a the time we spent to a t value for the total duration so we can do math dot or actually we can just multiply directly we get to do animation time divided by um move time and that gives us the T value uh and we might also want to um clamp this between 0 to 1. so this gives us the percentage of the movement animation right um oh the weird person is back okay you're you need to stop spamming the chat with just garbage um there we go um all right so we want to interpolate from the start to the Target and then we have our T value here and that's going to be the new position for our objects uh then we also need to be able to stop the animation so in other words we know that the animation is finished if T is equal to one right so if T is the one because we're clamping it it doesn't go above one I guess we can do do um I guess we can do this to avoid the warnings in writer then we need to stop the animation so then we just do it's animating equals false okay this should give us a very very basic movement animation um so so let's see if this works did any of you bring beer for this last session anyway encouraged it but um okay there we go we have our very basic movement you can press a key and a kind of very sluggishly slowly like drags itself across the board to hit the next square unit um okay and so now we have our very basic movement uh we might want to make this faster so we have the movement time here so I'm going to change it to 0.1 and so now we have a much much faster movement I'm going to slow it down a little bit so that it easy it's easier to see um to tell what's going on on stream we only have so many frames to work with so I'm going to set it at 0.4 and there we go here's our our basic animation right uh but this doesn't look super nice like it's it's very linear it's kind of like we immediately start moving we immediately stop it looks very very Jank right and this is where easing functions comes into play because this is where we might want to modify the T value so that we can add some sort of smoothing or or basically make a type of Animation um and Define that path over time and so here's where we can actually make use of our our old friend Desmos as usual um there we go okay so the current um the current function we have for our T value um is just the um this is kind of the identity function this is the function that just Returns the the input value right um so this is what our animation looks like right now we can also restrict the range so that we just see a relevant interval so there we go so this is our animation right now the x-axis is time and the y-axis is the um it's kind of also time but it's the it's the time we might want to change afterwards um and so so remember the y-axis is the output Thor Thor is poking plastic so here we can kind of start playing with like okay what if we change this uh this animation um so what if we do um let's see let's let's do this instead and then we hide that and let's see okay we can use that okay so if we have t this is our our regular old like straight up lerp right but what if we multiply T by itself we Square t now we have a different curve right um so this one it looks like it's um remember Xanax is the input and the y-axis is the output so in this case it's actually slow in the beginning um so because if we move linearly here you can see that the vertical movement is pretty slow and that is going to speed up near the end the closer to the the closer to one we get um and this is a very very basic type of easing function um so usually when it's slow in the beginning um then you would call that an ease in function um so we can actually Implement our very first easing function um so maybe we can we can do floats and call that ease in and then we have our our T value here and then we just do T times t so this is the function that we just did um so now we can apply an easing function here so we do do T equals ease in t and then let's see what happens let's change the move time again all right let's see let's go so now you can see that when I press it actually starts slow and then it stops very suddenly and that's because that's the easing function that we just used we told it to start slow and then stop suddenly and that's exactly what we're seeing here start slow stopping suddenly and we can kind of play with these functions however much we want we can Define whatever math function we want here right we can type literally anything but the crucial thing is that usually for easing functions you generally want easing functions to start at zero and end at one so start at Time Zero y value zero and end at the time one at Value one will it be accelerating if you hold the button longer no this is a predetermined animation you press a button and then it plays um so I'm not holding any buttons I'm just tapping them once um okay but usually you want something called an ease out function this is an ease in function but for character movements you usually want it to be more responsive you want the first input to like really really start off quickly and then you want it to slowly settle um and that you can also Define so um we can do uh one minus t uh squared and then we negate that so now we have an East out function so now this is kind of the opposite of what we had before right so this one starts fast and then it slows down that's usually the type of movement you want for for this type of character movement right when you're making like a basic grid-based movements um so this is called an ease out function specifically this is called a cubic ease out because we Sorry quadratic ease out because we have a um a quadratic exponent here like two is the highest degree of this easing function um and so um we can rename this to quadratic ease in then we can make another one which is the quadratic ease out uh and that one was um one minus uh one minus t squared okay so um I believe this would actually be the same thing as um one minus quadratic is in um and then we pass in 1 minus t so we're kind of hijacking the other easing function there I think that's the same thing because that's just squaring this one okay so let's try using the ease out function instead and then let's go go back recompile here we go let's see if this works and there we go so now you can see that it starts off fast and then it slows down as we're approaching the the end and this already feels much much better um this just feels great right like you're um you're pressing a button and it kind of slows down and we're doing this without the weird like lerp smoothing that kind of like always has this infinitesimal um like asymptotic fall off that's really annoying to deal with um and so this is just kind of playing an animation and we can really play around with whatever functions we want here um which is really useful um and so the uh there is a whole host of kind of standardized using functions that you can find online um there are many of them um and so so if you want to like dive super deep into this Rabbit Hole you can um should also talk about one of the the more popular ones which is the um which is this one uh except I got this flipped uh uh I said minus it might be minus I think I think I might I think it might be minus there we go yes it's minus um so this one uh is called the uh cubic in out because it's slow in the beginning and slow at the end so it's easing at the start and at the Finish and this one is is very useful in particular because this is kind of a universal smoothing operator that kind of just Smooths uh both in the beginning and at the end um you can sort of see that it's kind of similar to to the behavior you would usually get from a sine wave right um so so this would be a cubic smoothing function um yes smooth the operator uh yes so this this function uh is also sometimes known as smooth step um although smooth step has different definitions on depending on where you're using it uh but but yeah so so this is a very very common one so this is kind of the East and out or smooth step sometimes people separate cubic and out um from smooth step but I would call this the canonical cubic in out there's disagreement about what should be called what um and so so this would be equivalent to three I guess we can we can separate out a can separate out a t here um we can do t squared and then three minus 2T so T times t times 3 minus 2 times t this is called cubic in out uh three there we go how about his exaggeration going below zero and above one uh yes we can do that too now so this would be a smoothing in out so let's let's get that first someone asked how expensive these are to use uh they are very cheap because they they're very very like small mathematical functions uh they're very cheap to evaluate it's just a cubic polynomial um so in this case uh it is a um it is smooth in the beginning and smooth in the end and now we've just um now we've just defined the smooth little little movement right uh you asked about exaggeration um how how deep should I go into this um so so there is a uh there's a kind of a generalized way that you can express these functions uh and that kind of goes into a little bit about a little bit into splines um so the the general form of the general form of this type of easing function at least when it comes to cubic using functions is that we have some function f of t and then we have some constant based on T cubed plus b t squared plus c t plus d um and I can't use T here I think I think I have to to do oops is it upset because I've already defined t or oh it's probably just because I know it is upset because I'm using tea it's upset of both things okay um okay so so this is just a a generic cubic polynomial right we have a um we have a a factor of X cubed x squared and x and a constant d um and there is actually kind of kind of a general way that you can Define easing functions that I think is pretty useful um so if you if you consider uh now we just have all of these parameters we can just freely set them to whatever we want right and we have this constant and and all of that stuff um and so there's kind of kind of a useful way to parameterize this that I think is kind of cool um where we maybe we want to set the because we want the start position to always be at zero zero in this case in order for that to happen the constant has to be zero so the constant Factor so we can actually remove D immediately um and then we want the um we want the end point to always hit one here in other words we want the function when we evaluate this function at the value 1. we want it to always pass through here and so we can actually set that constraint up if we replace x with 1 here then we're going to get an equation that looks like this because X like 1 to the power of whatever is just one um and so now we have a relationship here um we have a relationship of a plus b plus C must equal one if it is to pass through this point and so what we can do is that we can define c in terms of A and B so we do 1 minus a and minus B so we're just scooting that over to the other side now so now we have C equals um one minus a minus B and then we remove the constant and now we have fully constrained this function to guarantee that it will always pass through pass through those points because we just mathematically told this to always do that right um and so now we can actually just kind of tweak this however we want uh to make whatever kind of kind of easing function we want right um so this kind of looks like a like an in back function where it like exaggerates a little bit and then then it speeds up toward the end um and and then you can do something like this and now we have sort of the sort of a similar situation there and so forth you can also um then we can also Define this in terms of the derivatives so maybe instead of using a b and c maybe we want to use like okay I want the derivative at 0 to be this and I want the derivative at 1 to be this um and I'm just going to open another graph because I've done that before and I don't want to I want to spare you the math um because it might take a while to set that up um uh okay I'm gonna have to search somewhere here where is it where is it hmm did I lose it oh no I'm not seeing it it's supposed to be called like her might easing or derivative easing oh I should have prepared this it's over um okay I guess we could derive the math um or think I actually have this in my notes yes here we go hell yeah so you can do the math to figure out how to do easing with derivatives so we can kind of re-express A and B to um to basically just set the derivative in the beginning and set the derivative at the end and then we kind of solve for what constraints that give us and so this is the equation that that pops out um and so this is also just a um a cubic equation so just replacing these there we go and let's restrict the range all right um actually let's not do that and so now what we're setting here uh the two variables we have is the slope or the derivative so if both of these are zero we get the cubic smooth step function like this is smooth step straight up but maybe we want the want to tweak the derivative at the end to be either positive or maybe negative um or or maybe we want to want to tweak this one in some way so so there are many different ways we can do this so if we tweak this one like this uh now the derivative in the beginning is pretty extreme it's a pretty high value and so now this one is going to overshoot uh and then settle here and so this would be an ease out back function which is kind of a nice way to parameterize kind of all of the cubic all of the cubic easing functions can be defined in terms of Just A and B in this case so that's kind of cool um but again there are many different ways of doing this type of easing um and so yeah uh all right do you want to implement this to share what that looks like as well or what do you think um maybe I should do that maybe I should just straight up add this function will that one go backwards at the end yes it would um Okay so this uh this is actually um kind of sort of like a hermite interpolation um but um so let's let's do um let's call it custom ease and then floats um the derivative at a and Float the derivative at B uh and that is this old function right here um so we're just gonna uh returned that uh uh let's see so d a d b d a d b d a uh then we need the the input parameter which is going to be t replace x with t okay slap in some multiplication symbols uh all right goat no so t squared is T times T and then we have t cubed which is uh t squared times t there we go uh D3 T2 this is C2 um let's just call them A and B that's confusing there we go uh all right so now we have our custom easing function and we can actually Express all of these in terms of the custom custom using function if we want um but uh but in this case uh we are we are going to do floats ease out back um all right so what was the parameters we said B to zero and a to five um we can set a to whatever we want kind of depends on how aggressive we want this one to be but I guess if we want it to be visible on stream it probably should be pretty pretty aggressive so let's set it to five um you can make it a parameter even if you want to um so a is five b is zero and then we set the um the time parameter is just t so now we have a new function called ease Outback so that one is going to overshoot um and so now we're gonna have to separate the time from the position T value because we're checking if T is greater than one to tell if the animation is done we need this to be the original t value here and so so we might want to separate these now so I'm going to call this T time um and then we're gonna have float T value so this is the remapped value uh so that's we're going to use that one for the alert and remember unity's lerps clamp by default so we don't want to call lerp in this case we want to call lerp unclamped uh this allows it to extrapolate uh so we want to make sure to call that tea time is it t time I don't have any teeth I have water so I'm gonna have water thanks for the reminder or did you mean break time oh it is kind of break time anyway I'm gonna continue for a little bit all right transform position equals LARP and clamp we're using the the output of the easing function in this case we're still using the time to check when the animation is done um and so the the time in this case is the x coordinate of our graph and the T value is the y coordinate of the graph um okay and so this should give us the ease Outback function see what that looks like this should look a little bit squishier all right and so now you can see that it overshoots and then corrects back right it does it does a neat little little overshoot I hope it's visible on stream uh you might have a lower lower frame rate but hopefully it's visible so now it looks a little squishy it kind of like whoops overshoots and then slides past and then yeah so it adds a little bit of a juiciness to it which is nice um and of course um these functions can be absolutely anything you can you can Define these using whatever kind of math you want um and a an even more useful way of doing it Which is less fun because there's less math involved but it's more useful um is to actually just straight up use an animation curve for this so you can just do public float or sorry public animation uh curve and then we can call that movement um animation and then we instead of doing ease Outback here we're just going to do movement animation dot evaluate at T time so now we're going to use that animation curve to this we're going to recompile there we go so now Unity has this thing called animation curve which you can edit directly here um and so now we've just made a linear curve and it has a few presets built in you can see that it has the the ease in it has ease out ease in out um and then a few other functions as well um and so what's really neat about this one is you can add keys so so this is kind of like more of a traditional animation workflow uh where you have way more control over how you want this to to behave um so this is more like the workflow for like an animator so they can tweak this to to their hearts content to make um make their their perfect little wobbly movement um there we go and kind of the The Secret of this one is that this one each curve is also defined by a math function in this case they are defined by what's called a hermite math function and together all of these make up a spline so what you're looking at here is a one-dimensional cubic hermite spline sorry a non-uniform one-dimensional cubic hermite spline if you want to go super technical I've been digging extremely deep into spline size of late so I have a ridiculous amount of knowledge about splines now um but yes so let's explain um so now we have we're using the animation curve to do this animation um so we we of course have way more flexibility when using an animation curve or a spline um and so so yeah so now we have this very very wobbly animation what's hermite again um we could go into splines if you want to um it kind of depends on how much time we have and how much you want um want these things um like how much you want like because we also need to cover abstract algebra so I don't know if you want to hear about splines I think the I think splines was the least voted on of the three main topics um well we could go into it of course um so so this is kind of just the the basics of the um of how to do like procedural animation where we we have time values and code and then we're kind of applying them or using them either through like mathematically defined easing functions or we can use animation curves that we've kind of um that's a bit more easy to author like by hand um where you have a lot more control over what you want this animation to be like um so this is a very very useful tool um okay um could you backtrack a bit on how did you make those parameters be the derivatives of each point uh yes yeah we can do that and that's going to be a bit of algebra but uh we can do that um let's delete it straight up there we go um okay so uh ax cubed plus b x squared plus c x uh plus d um okay um so we we know that we need um we need the the uh we need to start at zero so we need the D parameter we can remove uh we need it to end at one which means that that's the thing we did before we kind of tweaked uh one of the values here to be one minus B minus a um so C is no longer required so now we now we forced it to pass through uh these two points uh then if you want to make the derivatives match uh we need to find what values should we use for a and b if we want that to be the case right so we can just write those equations so so let's define the start derivatives um let's use capital letters for this um or or actually let's use d0 and D1 that's a little bit more technical but maybe that's good um okay and then then we basically just need to do the uh we need to calculate the derivative of this um you know how to differentiate at this point um so uh we take the exponent move it down reduce the exponent by one same thing here take the exponent to move it down reduce it by one and then this one is just a constant because X removes uh is is removed like that right um okay so this is the derivative that we have here um so let's see all right and so now our requirement is that we want the derivative at oh maybe I should zoom in a little bit I don't know how easy this is to read um we want the derivative at zero to be equal to d0 right in other words this function let's call it f Prime of x when this is zero uh this should equal D zero so we can we can simply write this function um equals d0 can kind of ignore the graph for a while um and then we solve for one of the variables and an X in this case we know that that's zero because at Time Zero we want the derivative to be d0 so X is zero so every term of X disappears here because we multiply them by zero um and now we have the value for d0 just kind of straight up right uh so now we know that d0 um or no sorry we're not solving for d0 we're solving for a um so let's undo that uh okay or solving for B it's all for either of them so if you want to solve for b then we need to do uh we need to subtract one um and we need to uh add a to both sides um and then we negate both sides so we multiply both each side by negative one so that's going to flip all the signs so we're gonna just flip all of this and now we know the value of B um so now we can actually remove this B slider because now we've calculated the value there and now um we can set d0 um and so if we set it to zero the derivative is flat here we increase it we have a positive derivative if we could do negative we have a negative derivative and so forth right um and then we can just go through the same process but for the derivative at Value one uh and so we do that and then we say that this should be equal to D1 when X is a one so replace x with one so all of this is just going to get multiplied by one um and then we need to solve for a uh but in this case we have a few unknowns here because B um we should replace B with this equation here so we're going to do a substitution um and we can actually simplify this a little bit because now it's a little it's a little bit messy uh so we have 3A minus a it's going to become 2A 2B minus B uh is just B and there we go um and then we know that b equals this so we can just substitute B by that whole formula uh so now we have um Let's see we have D1 uh equals all of this so we subtract another a so that becomes just a and then plus one plus one is plus two and now we can solve for uh a right so uh we we can do we add d0 to both sides oops that's multiplying I don't want to multiply and then we subtract 2 from both sides and now we've defined both A and B um and now we can remove the a variable and there we go so now we have the function where we set the derivative at the start and we set the derivative at the end um so so this is again you're kind of like you set up your constraints and then you solve for the unknowns and that's exactly what we did in this case um and so so yeah we set up the uh the the four constraints we had was um just you just to clarify this a little bit more um so the four constraints we had we had our our graph right um and it goes from zero down here to one um so the constraints we had were when at zero we want this function to return zero right um at one we want this function to return one this pins it to these two points this forces the function to always pass through these points right so if we apply these two constraints that's what's going to happen and then the second constraint was that we wanted the derivatives um in other words F Prime the rate of change at zero this should be equal to d0 and then the rates of change in other words the derivative at the end should equal D1 so these are four constraints right we have four equations that constrain the the whole curve in a different way right um and and then the an appropriate function for this is the the cubic function because we we have four constraints that means we need a math function with four unknowns and that just happens to be the cubic in this case if we want to use a polynomial so a um a x cubed plus b X squared plus C X Plus d so in this case we have four unknowns we have four equations and then we can just solve for that we could just straight up work out that equation because each of these constraints allows us to express each of these in terms of the other variables so this is just kind of kind of basic like equation solving um and so that's what we did for this easing function where again the derivative is the slope so what we have control over is we set the slope here and the slope here and then it kind of solves it for us um to to set this cubic polynomial to to match that range based off of the values that we choose if both of them is zero we get the the classic like Smooth step function um all right so that's what happened um I took a bit of a shortcut I did these first and then I hand waved the other two but now we did the other two as well um okay algebra imagine that um all right that's that's what we did um any questions so far there's been Dead Silence from from chat for the most part um don't suppose you could get the value of the curve and build a road on that instead of creating our own bezier you can do that um you can you can Define whatever function you want um so you you can totally do that just vibing okay that's good um all right hmm typing typing typing oh yeah um someone asked if there's a name for this um yes um so this is called cubic hermite interpolation in this case it's specifically one-dimensional interpolation um and we've also instead of having custom values here we just have specifically zero to one um but you could set custom custom values here if you want to um so if you wanted this to be I don't know value one or sorry value zero and value one uh then then that's hermite interpolation umit if you're a French I guess solving for this gives you a hermite spilling a rather harmoid curve that you could make a harm right spline out of if you want to um so yeah this is the the hermite hermite interpolation cubic hermite interpolation um okay and so so the um you can actually solve this the same way for uh 3D curves uh where you have a starting point and you have an end point and then you specify a starting derivative in other words velocity and then you specify an end derivative which again that's velocity right and then it can create a curve uh from those two data points and this is the hermite curve in 2D instead of 1D uh so this is the hermite uh kerf is specifically the cubic hermite curve so you can see that this is kind of similar to the the type of interpolation we did with the bezier Curve right uh but instead of specifying like arbitrary points here and we're giving it velocities um just straight up velocities I want the velocity beginning to be this and with the velocity at the end to be this and then it just creates a path that um follows those constraints that you've given it um that's the cubic carbide curve um and I guess this is a good uh good segue into a good Segway into splines so I don't know how much time we have uh I guess we'd gone for an hour now do we do a break or well what do you think do we just do we just like steam ahead break sounds good okay Let's do let's do a break okay we're doing a small break five minute break okay it's 14 25 right yeah okay all right um only live on YouTube yes I am only live on YouTube right now uh in fact I am not allowed to stream on both YouTube and twitch at the same time unless I want to break my twitch partnership um and I'd prefer not to do that it seems kind of pointless so I'm not not allowed to simult stream um wait someone make a french fryer meme wait was it because I said egg meat I don't know how to pronounce his name it's Charles hermite that's the American pronunciation butchering the French um sort of white on stream lectures on Twitch is it a restriction from future games uh I used to do all of my lectures on Twitch I wanted to try YouTube I just wanted to see what is the audience maybe I can pick up some more people than on Twitch or maybe less people um and I just wanted to to see what the audience was like so it was a bit of an experiment um and so that that was why um I was just curious to see how it would work out and yeah it's been an interesting experiment uh I definitely have um I definitely have much less viewers than on Twitch uh usually on Twitch when I do these streams I tend to get like 200 to 250 viewers um and so um so I usually get more viewers on Twitch I've noticed that during these streams the first one I had a lot of viewers because I kind of tweeted about it a lot but then for the for the consecutive ones I kind of stable stabilized at like 90 like 80 to 90 um and so yeah which I didn't really know what to expect either it could be the case that my YouTube audience is not following me for live content um and so maybe I just don't have a lot of people watching my live stuff on YouTube um or it could be the case that maybe YouTube's algorithm would push my streams so much that I would get way more viewers than I would expect um either of these could happen and so um yeah so it was an experiment uh I don't know what the answer is I just know that I have less viewers but I don't know why and so it's kind of hard to um it's kind of hard to figure out figure things out I guess I would have to check how many people um I guess I would have to check how many people are how many of the viewers are my followers or subscribers on YouTube versus how many new people are coming in um do you have the same amount of weird backseat backseat teaching on Twitch or is it less more there um I have more viewers on Twitch and so there's more backseating on Twitch um so it's worse on Twitch but that's probably just a just a just a like factor of the number of viewers um oh I'm talking concurrent viewers William not a total amount of views so concurrent viewers is much higher on Twitch um yeah [Music] yeah you can see people quitting after each video they got tired of it [Music] um okay backseat math teaching is such a strange concept I think a lot of people want to inject more information uh they also want to come across as knowledgeable and smart so I think a lot of people just kind of do that um and sometimes it comes off as a little bit weird uh because the thing is that like um so so quite often when I talk about the um when I talk about say the dot product like the beginning of our of our lecture I have a very very very strong focus on linear algebra like we do a ton of vector math and we just talk about the dot product the dot product and the the projection and all of that stuff and matrices and spaces I do all of that stuff without ever touching trigonometry and this is intentional like that this is something I'm intentionally doing I'm intentionally withholding information in order for us to focus on that later right but every time I talk about the dot products and I write this equation every single time people on YouTube go talk about the cosine to talk talk about the it's also it's also the cosine of the length of the tuvette you need to mention the cosine don't forget the cosine and I'm like shut up I know I'm intentionally leaving it out stop flooding my narrative with spoilers and we're gonna get there later just just chill your beans and so yeah that's kind of it's a little bit frustrating when people like um I don't know sometimes it feels a little bit like they're putting I don't know railroad track in front of me and it's kind of annoying um is it that pad to spoil stuff with math though I mean if you are in a lecture where you're going to talk about that later it can be distracting right because you're not supposed to like I've designed the order that I talk about things um very specifically um and so I don't want that to get distracted and distorted and messed up right but otherwise if you're if you're just learning math and you're okay with just random information that of course that's good to just I don't know have random information available to you but in my case it's a little bit annoying when I'm like specifically trying to um specifically trying to have a narrative thread to it all um huh okay all right um yeah I don't know like to me it is spoilers um I I don't um yeah I do see it as spoilers because I I do consider it the the narrative thread of at least the things we talk about from the first few lectures um well that might be a flaw in me but I think it's the best way to go about it but I I don't know I don't know uh or I'm just grumpy that people are vaccinating and I'm trying to come up with excuses as for why I'm grumpy um okay all right oh is Kristen not doing assignments for you maybe he isn't I actually don't know I just thought he would um oh that's in part two oh nice okay then I don't then I don't have to do anything I don't have to send send part two's it's always good to ask you sir though get clarification on how the assignments are going to work out okay just had to ban someone from just had to find someone from chat because they were really distracting and weird uh okay all right uh [Music] should we resume or should we wait for um should we wait for Crystal to respond or should we just just Steam on ahead teaching to a body of students with widely varying levels of math knowledge is difficult too yeah it is it is hard um some of us have degrees some of us have meta triangle once but it didn't phone back yeah sadness um and then there's also people who did go to school for that stuff and then forgot everything I think the the strategy that I usually go for is that I have a pretty fast pace um and when I talk about the basics I try to bring in different perspectives and contexts that make it interesting even for those who already know those things that's usually what I try to do um just not to bore the people that are like oh I already know the dot products um and then I try to try to add more context to it um whether or not that works I don't know but I hope it does I think it does um okay we're off break uh we're we're resuming um okay show your presence react what is a long cat that's it I'm uncomfortable by this long cat uh all right oh what a what a textbook oh God textbooks textbooks are so boring I don't know how they fail so hard at making text look so boring oh my goodness okay um let's let's resume where were we uh we were talking about uh hermite hermite curves um all right let's see it is 14 30. all right I think um I can briefly talk a little bit how splines work and then we can continue to abstract algebra how does that sound I think the uh splines we don't have to go super deep on it um I can sort of kind of just explain the the basics of it um and so the the basics of splines is that it's it's effectively like taking a set of Curves and stitching them together end to end um so we we covered the uh bezier curve before uh where is the bezier here it is so this is the bezier curve right we specify a bunch of points and it creates a curve between those points uh now if you Stitch multiple of these together um so maybe maybe you're creating a longer path uh then this is usually what we call a bezier spline and so you might have seen this type of control before where you have these handles uh that you can drag around um and then it can create this kind of vector-based shape and this is actually this is actually the exact tool that photoshop uses and illustrator uses for their um pads um and so you can kind of you can see how inaccurate I was um and so so now this is this is literally using bezier curves um like photoshop's pen tool is a set of bezier Curves stitched together um so so this is just um um yeah cubic bezier curves you now know the math to write this you can make photoshop's um photoshop's pen tool using uh what we've already talked about you know how to make a cubic bezier curve and I think you would know how to stitch them together end to end right and so yes you can make Photoshop you too can make Photoshop um no need to pay Adobe you can just you can just make Photoshop um and so so this makes a spline um now the topic of splines goes incredibly deep depending on how far you want to go um and so the um there are many different types of splines um in that case that was a cubic bezier spline um you can do the same thing with the cubic hermite curve where you can just keep keep specifying velocities and points right you want the the next points to be here with the velocity going in in this direction um and then you you would keep defining shapes like this um and then the the cool thing about the hermite spline is that you do specify explicit velocities um which is kind of cool so if you want to animate something along a path the hermites line actually lets you say I want this to go this fast at this point um and so that's that's kind of the power of splines and um you already and you already saw the um the little animation we made um in unity so this is also a spleen um we we basically set the point um and then we also set the derivative remember the Splat the um the slope is the derivative of a one-dimensional curve and we're basically just setting the slope here and so that's why that's why this is a hermite spline but it's a one-dimensional instead of two-dimensional um excuse me um okay and so um where did my window go [Music] um and I happen to be working on a video about splines that I've been working on for about a year now uh that I'm gonna release on YouTube soon TM um and it's a video about splines and continuity which is a very important property as points so if you want to dive super deep into splines how they work all of that stuff you can just watch the video when it's released it's going to be it's going to be out and maybe a um maybe a few weeks so so this is going to be out at some point um and yeah um so here's so here's another example of of the uh her might explain the use for animation um so so this is kind of how it works when you're animating something with unity's animation editor um so so we set up these splines that defines like the position of an object and then you do the same thing for like the angle so now we're animating the angle of this Cube using a spline as well then maybe we can change the scale over time using a spline so we're just using a spline for all of these different properties in order to animate um and this is effectively how all animations and games work all animations every character animation uses splines um either they use the hermite spline or they use the linear spline because sometimes you optimize that way um and so it's a very very very broad uh topic where there are many different types of splines that are many different properties um yeah so that that's kind of that's kind of the the uh the whole universe of splines it's it's super useful for for animating objects and that kind of stuff like defining paths and and whatnot um yeah and so I don't know how much I should go into depth about splines um so maybe we should should hop on over to um hop on over to talk about uh abstract algebra if you if you're feeling ready for abstract algebra I don't know I don't know if you do are you feeling ready how's are you feeling feeling reditude to just breach that subject not a chance in hell do it okay um let's see when do we we have one and a half hours right it's um it's a calendar I think that's a good amount of time to to talk about abstract algebra um okay I might mess this up because I have never done an improv lecture on abstract algebra before and so so I'm not sure how well I'm gonna explain this and I also don't know as much about this as I do about the the other topics I've talked about um and so I'm gonna have to expand the canvas uh seven thousand eight thousand pixels I don't know [Music] um oh boy okay um I'm gonna need my notes later on this oh great um completely lost no not the Freya spline [Music] um okay um let's let's um where do we start okay let's let's start with let's start with the imaginary number the imaginary unit it's a very it's a very fascinating topic um so you probably heard about this one in school I hope you did um and so let's zoom in a little bit um also try to keep talk about other things in chat a little bit less than right now because I think it's more than one page just full of talking about Photoshop uh uh yeah try to try move it to off topic there's the thread with off-topic conversations if you want to hop in there just because it's a little bit distracting for me to like try to catch up with questions and whatnot um okay um so do you imagine the imaginary unit um here's here's a here's a fun fun little little math problem okay are you are you ready I'm gonna give you a task I want you to solve a an equation all right I'm going to need to solve uh this one okay we have X x squared uh sorry I need to zoom in x squared um plus one equals zero um what is X can you find X in this case um clearly this might be a little bit of a trick question um but okay maybe we can we can try to figure this out maybe we can go to uh decimals right we have our graphing calculator um and let's go to a new one and so we can just type this equation in we can do x squared plus 1. so when is this equal to zero in other words when is the Y value zero of this graph um and the initial answer is it's impossible right you would just say it is never zero we can clearly see that it only gets as close as this right um it's one unit away from zero and then it just shoots off into positive Infinity right on both sides uh so it seems like it's it's kind of impossible to to solve this equation right um but then some mathematicians said what if we solve it anyway what if we just invent a solution to this so we can Shuffle this around right we can say that x squared equals negative one we need to find a number where if we Square it in other words multiply it by itself it should become negative one um this number doesn't exist in regular algebra there is no number we can put here that solves this equation so what we need to do is to kind of invent another algebraic symbol that can represent something that solves this um and so what that is called is the imaginary unit and that is called I so it's just a lowercase I um and there we go um okay uh continue the square root to take away the Square from X on both sides uh well then you need the square root of negative one and then you're back to the same problem right what is the square root of negative one uh which is kind of the same issue uh generally you can't do the square root of negative numbers it's the same problem but just expressed in a different way um and so we've kind of kind of invented this symbol that just satisfies this formula um and what's really fascinating about this is that it kind of seems like it's just kind of this um arbitrary concept it's kind of like okay what's what's the use of this like what's the point um but this is actually the entire basis for things like quaternions um this concept is Central to make quaternions work the way that they do um it kind of just so happens that this invention turned out to be extremely useful in ways that they probably didn't expect when they begun like testing this out um and so you might wonder why like how how did this turn out to be useful um well let's let's explore this a little bit further um so this is the um this is the sole definition for the imaginary unit so this is this is how we Define the value of I okay um and so this is the thing about abstract algebra that is just this is the abstract part right like we don't really we don't really know what the contents of I is and it's kind of beside the point like all we know is how it behaves when we Square it right that's all we know but then from this we can derive a lot of like kind of interesting and weird properties um and so for instance um here's here's a question um or actually let's let's uh let's color code this um I think I think I should be purple because purple looks like mysterious and alien right I think I think that's a good color um okay um so here here's the question uh what is i to the power of three what what is that can we figure this out given the information that we have here um it turns out yes we kind of can right because we know that I to the power 3 or I cubed is the same thing as I times I times I right um which is also the same thing as I squared times I um which we already know that I squared is negative one because that's the definition of the imaginary unit right so I times I is negative 1 which means that I cubed is simply negative I um negative I and that's kind of kind of weird and and fascinating isn't it or at least I think it is um and then we can go further let's go one one step more we have I um to the power of four do we know what this is at this point um well okay so if we this we know that I times I equals a negative one so clearly this has to be negative one times negative one right um which that's that's just one um and so we can continue doing this and we can also go the the other direction um and so I don't know we can let's let's add I cubed here or I squared this is the definition so we know that this just equals negative one um and then we have I to the power of one uh which that's just a regular definition with with something to the power of one is just that thing itself so that's just I um okay cool that's that's all that's all neat isn't it um well when we go further than this that's when interesting things start to happen um and so if we then go further if we do I to the power of 5. what is that can you can you make a guess what I to the power of 5 is um assuming you don't already know the answer but you should be able to derive it given given all of this uh I yes because we know that I to the power of 4 is 1 and then we just multiply 1 by I and then we'll end up ending up with just just I right and now you might be able to see that something something fishy is about to happen we can do this again we can make a i to the power of 6. and the next one is going to be negative one we can do I to the power of seven and we're going to go back to negative I um whoops sorry we can do I to the power of 8. uh and that is one and so you can probably see that there's there's a cyclic nature of this uh the pattern for all of these repeats itself after after four occurrences right um and so so this pattern is exactly the same and this actually holds in the other direction too so I to the power of zero is one I to the power of negative one um just again continues this pattern um and that that's pretty fascinating isn't it like it looks like we have this kind of like circular or cyclic Behavior Uh just from this one definition the the only definition is that I squared is negative one and we we now constructed this like algebraic constructs that can make this repeating pattern um okay what about the in-betweens we're going to get to that uh we're we're getting there um okay and so we can kind of like um we can kind of think of this as as a geometric concept um so what if we you remember the number line the the real real number line where we have all of our usual numbers right we have zero in the middle we have one somewhere here one negative one over here and so forth right and then two three Etc uh so this is called the real number line there we go so that's the real number line and that that's all that's all well and good that's useful right but just like we did with vectors we can actually just kind of add another coordinate system or another line perpendicular to that one um so I'm just going to move things a little bit uh we're gonna make it purple we're gonna stick to the to the to the mysterious alien Vibe of uh the imaginary numbers uh and so this um is the imaginary line um imaginary kind of makes it seem more mysterious than it is but but that's fine I forget if imaginary line is the the correct term for this just just pretend it is um um all right and so along this line uh we have our values of I right so so we have I over here and then we have negative I over here um and then we can actually just kind of continue right like we can multiply I by two for instance and so up here we would have 2i um and so forth so we can kind of kind of like we've now constructed um a a space of possible numbers um and and this is called the uh complex plane um so we should probably move this one um did you all right so so the coordinate system we have here is the the complex plane okay um and so so we can actually Define coordinates now uh because if we have a number um say we have um two two plus I the if we do 2 plus I we can actually write that as a coordinate because the the real number line like 2 is the real part of this number so 2 is going to be somewhere here and then I is the imaginary part and that's kind of like our y coordinate right and so that's going to be a point on the complex plane um and so we're kind of expressing this um using both imaginary and real parts and so and so you can actually kind of Express them as a vector if you want um so you can actually write this as a an imaginary Vector with components two and one because we're multiplying I by one right and so if you want you can write it like this usually you don't do that though and it can also be a little bit confusing because you you might accidentally mix them up with regular vectors um but that actually gives us a point uh in this along this real number line [Music] um all right so now that we can express points like this um then can you use I in unity uh yes C sharp has a a complex data type um so so this is called a complex number all right okay so so this is kind of like a vector in the in the complex plane right we would just Define this coordinate um and just like any other plane we can just pick any number uh we can pick maybe like this point here um so so this would be uh like 0.4 um uh plus uh 2i right um and so so this point right here we can also Express that so so any any point in the complex space um is very similar to vectors in that regard right um okay but they have these weird rules um so let's think a little bit more deeply about these rules like how do they actually function um well uh we know that I to the power of zero so let's let's add that one too I to the power of zero equals one because most numbers to the power of zero equals one so that's nothing special right um and so I to the power of 0 lies here right because because if we think about this in the vector form this is basically like writing uh one plus um zero I so so there's there's nothing on the imaginary component that's just zero um and the same thing goes for this one um this is kind of like doing um 0 plus I so now we express these as complex numbers right we have a a real part and an imaginary part so these can be coordinates in this plane so if we start at I to the power of zero uh that is going to put us here at the um I don't know what color to use here um so so maybe this is i to the power of 0. and then when we get the next point it goes from uh it goes from one because again it's a one along the real number line and zero along the imaginary line um and then if we do to the power of one we get I and so what that does is that it's it kind of like rotates it if we get a number up here um and then we go for the next one where the imaginary part is zero and the real part is negative one and so that gives us a point right here and so you can see that we're kind of cyclically moving like this and then the next one is negative I so we're down here and so forth um and so so what's special about this is that this actually starts to kind of look like rotations right um and so you might be able to already tell how how this might be related to quaternions right because they they work with um um they they work with this type of cyclic Behavior just like rotations do uh technically it is I mean all numbers are imaginary because x equals X plus zero I um well kind of but also kind of not it's true that you can express any real number as a complex number but usually there's no purpose in doing that um like like you can say that you can invent a number system um that is called uh regarble um and then they're like okay I have these like I have invented a new symbol called word garble that looks like um looks like uh this it's like a like an alpha but it's rotated um and any real number can be expressed as five plus garble times some number like um seven or whatever so like yes you can express every number as having uh zero garbles right um but you don't really do that because it's pointless because you have zero amounts of garble right um and so so what the um so if something is on the real number line um your garbled pill um if something is fully on the number line and some everything else is zero we could just call that a real number right like there's no reason to to bring in the the other things here um okay um so it's more like you can express every number as a complex number if you want to um but usually there's context for that um okay um all right um okay so uh what's the formal way of saying it real numbers are contained within complex numbers um I think it's a subset yeah um okay but by the same token like we you can just say that they are a subset of the regardable numbers too um so it's just a matter of perspective and the purpose and the like reason you want to call it that right um in the context of the complex plane it's useful to still call these points complex numbers because we're we're still making use of the laughs I came with garble you're not supposed to remember the garble that's the least important part of this um um okay stop it is sleeping out of my control oh no okay anyway um okay who so someone asked what about the numbers between um the numbers between them nothing to do with garble unfortunately um so so what about numbers in between we seem to have this like repeating pattern that kind of hints at some other relationship um well um some incredibly smart people um figure this out um and I actually found a way to Traverse the complex plane in a perfect circle in other words the they found a way to connect these absolutely perfectly um it is kind of hard to read up on exactly how that process went um but all you need to remember is that this was actually possible um and the the formula for that remember we've been doing like we've been doing powers of I that's kind of how we've been traversing this very very basic Circle right um and someone figured out something really really cool um and this is this has often been quoted and cited as one of the most beautiful formulas in mathematics and I think I agree because I think this is absolutely Bonkers that someone figured this out um the what they figured out was that if you want to figure out the the point in this circle then you know you you we want this to be a circle so we of course this has to be the cosine of of some angle right uh so so we're going to just be like okay we this has to be the cosine of the angle and that's going to be the real number uh and then we want to want the imaginary number uh to be the sign or or rather I times the sine of some angle right like this is what we want to solve like this would give you a circle this is literally what would give you a circle because remember cosine gives you the x coordinate and the x coordinate right now is the real number line and the y coordinate is the imaginary number line so it should be I times that factor right which would be the sine of the angle and someone actually solved this um which is which is really cool uh and so so the the solution to this is that if we take the mathematical constant e and raise it to the the power of um the power of the imaginary unit uh times the angle um Theta we we get the solution this this is the the relationship um and this is really weird that this actually works out um this is kind of kind of wonky that we take this this number e and if you don't know what e is e is just a number like two points something something um and this is kind of the Magic ingredients where we if we take e to the power of the imaginary unit multiplied by the angle we actually get the cyclic Behavior we literally get a a circle um and so we can directly get the imaginary number on this circle based off of the angle Theta um using this formula um so we just take take e to the power of I times Theta and that gives us a cyclic Behavior you might have seen this written in a in a special case um so there's a there's a special case formula where usually you see this written as e to the I multiplied by pi usually so e to the I pi equals or Plus 1 um equals zero and this is called Euler's identity and this I think is Euler's formula uh yes Euler's formula and this equation in particular has been described as the one of the most beautiful formulas in math um because it kind of involves um the all of the most important constants in math like we have e we have I we have pi and we have one and we have zero it's it's pretty wild that like all of this kind of conspire to create the circle um in the imaginary plane um and of course since I'm someone who doesn't like I uh or doesn't like Pi I would rather Express this using Tau um so you can do this using a Tau as well so using Tau it would be e to the I Tau um equals one or if you really want to have all of these numbers in the same thing uh then you can you can you can also just do minus one equals zero and so so this is Euler's identity all right um and so so this is kind of cool um and if you if you don't if you don't know what um you don't know what e is uh e is kind of interesting in its own right um so just to show an example of where e comes from let's say you have an a function f of x and we are doing a constant a we're doing a to the power of x so now we have an exponential function so let's change the range a little bit um oops that's not that's not a good range um so this is just the standard exponential function we have a number 1.7 to the power of X and then we can modify this this number here now so this is just an exponential falloff where we can tweak the first um um yeah we can tweak the the base of this exponent um now you might ask yourself uh what is the derivative of this function well we can let decimals calculate that for us so this is the derivative the the rate of change of this function and then we can just kind of add the the other derivatives just the rate of change or the rate of change the rate of change and the rate of change on the rate of change and so forth in other words we have position velocity acceleration jolts and so forth um as we can kind of just keep adding derivatives like this to our heart's content um and here's here's something fascinating that can happen for a very particular number here now watch these lines as we as we move this number around to see what's happening here they are all converging and if we keep increasing they're going to diverge again and so it's kind of like wait why what is this number like why are they converging specifically at some weird like number around 2.7 like like what's up with that uh like we can zoom in a little bit more and we can try to refine this and figure out exactly what this number is uh this number is e um and so it's one of the one of the fundamental constants in mathematics um so so you have that here if you want to want to learn about e and how e works and so what e is is that it is the unique solution to the formula a to the x where it is its own derivative uh which is which is kind of kind of weird like if you take the derivative of a function um you get the same function out of it an e to the power of X is one of the few functions um depending on how we Define functions but it's kind of the only function that does this which is very very very unique um uh with some exceptions but we don't care about those exceptions and so this is why e is a very like special number um and so e is not like I where that is like a weird thing e is just a number that is uh two points 2.71828 Etc right it is just a number uh that's what e is um so like e and Pi um both of them are just just numbers uh but but I is not a an algebraic number like this um so that's what e is it's just kind of the magic constant where it is its own derivative um and so somehow this constant where you have this constant that is its own derivative if you raise that to the power of the imaginary unit times the circle constant or an angle you get the circular Behavior and that's the that's Euler's formula and this is Euler's identity um I have no clue how they worked this out um that math goes beyond me I Tried reading reading up on it quickly yesterday before today but I couldn't like quickly grasp it something related to the Taylor series and differential equations I think um but yeah and so and so this is um this is the imaginary unit okay that's that so far any questions I don't know if I can answer too many questions about this because my knowledge about this is more limited than many other things uh where does garble fit into this um I haven't quite figured out the algebraic properties of wagarble um but uh but we'll we have to figure it out um how useful is it to have complex stuff to Game Dev um so mostly in Game Dev this is only used for quaternions nobody uses this for anything else pretty much um and if they do they probably don't have to um yeah so this is like almost only related to to quaternions um I don't quite understand the logic of how I Square the cube Etc repeats all of that follows directly from this rule um so if you if you know that if you square them um it'll become negative one uh and and that's it from that you can derive all of these numbers um yeah um okay uh yes you you will see the final notes uh this is the final math lecture yes you're not expected to memorize all of this that's why this is a bonus lecture um explain this then I have no clue why your colleague used imaginary numbers to solve that problem that seems completely unnecessary to me um okay all right um so the the reason why it repeats is because that's what happens from this rule um like I I'm not entirely sure how else to describe it apart from repeating what I already covered first um like the um like if you look at this equation right here if you just focus on this one uh if you take I cubed that's the same thing as um I times I times I right which is the same thing as I squared times I and we know what I squared is right we know what that is because that's that's our definition I squared is negative one um and so that's why we know that I cubed is equal to negative I um and then we just continue to do this for the rest um so we we just applied this rule over and over and that gives us the answer to all of these and so that's why the more we continue uh this the more we continue to to raise this to the power uh of some integer this pattern is going to repeat forever and ever um because of the rules of how we multiply these numbers um okay um all right is a negative I squared equals one uh yes well it depends on what you mean by if that negative is inside or outside um if you mean negative I squared uh or if you mean um negative I squared because these are two different things because the the squared has operator presence um okay um all right any other questions before we move on to a different type of abstract algebra um ooh I don't know if we should go on break maybe we shouldn't do break because we don't have that much time left um okay um and so this this whole idea can go pretty deep depending on how far you want to explore this in various different corners uh but in terms of Game Dev again this is mostly relevant to uh quaternions um and and so so this imaginary unit um everything literally all of the discoveries here everything related to how e to the power of the imaginary unit times an angle in radians happens to follow a circle Euler's identity all of this stuff everything is a natural consequence of this one definition everything like this is just by trying this idea uh like what if there's a number then we can square that becomes negative one suddenly all of this pops out of it which is kind of like magic to me it's pretty pretty wild that this is even possible um and I think that is kind of kind of it's kind of fascinating um and so the you can actually do similar things like this in different ways and that has actually been done um and this is a very very very well explored field um the feel of abstract algebra and so you can you can make up other rules um so so what if um uh what if what if you make up a another one um so so for example um what if you say that we have this number right here but I've forgotten the name of it's a Greek letter I think um what if we say that this one squared equals zero but but here's a caveat this this value um is not equal to zero so now we've we've just kind of like invented another algebra we just have have this rule right here that we have some some some imaginary unit or not imaginary we've invented a new unit uh that went squared it becomes zero Epsilon is this Epsilon oh maybe it is Epsilon um and this is also a thing that actually exists this has been explored um so instead of a complex number uh there's a concept of dual numbers uh so this is the Dual numbers I'm pretty sure that's the one that squares to zero I just need to double check now um just to make sure I don't uh yes okay yeah so so this is called a hyper complex number system so both of these are hyper complex number systems um and you can actually do this um you can keep doing this uh there's another one uh where you say that okay what if we have something that squares to one but it's not one and then you follow the algebraic rules just to see what happens um dual numbers happen to be useful for something called automatic differentiation if you use dual numbers when you're doing um like polynomials dual numbers can actually help you get the derivative of functions kind of automatically uh which is which is kind of neat right um you can keep saying you can keep doing this as a mathematician giving out a threat yeah be careful don't go too far um I'm not gonna go too deep into the Dual numbers um again there's another one where you can square it to one um I forget what that's called uh that's also apparently useful in some cases um but you need the case um so this is a concept of making up a symbol giving it algebraic rules like this squares to zero but it's not zero um like these kinds of things um is something we can kind of just invent and so maybe I can make up some rules for wagarble that makes that a useful concept who knows um maybe maybe it's something like garble squared uh or or garbled to the power of wagarble is the regardville I don't know and it's not one um okay um our dual numbers the same as pseudo numbers or pseudo vectors uh no uh but we're going to get to that later um soon um okay all right um let's continue uh or just one thing I need to check my notification um why does unity even use quaternions when Euler is easier the only reason like the one reason we use quaternions is because they are computationally efficient that's the only reason um there is no other reason quaternions are extremely annoying and complicated um and so it just they just kind of suck uh it just so happens that they are very useful because they are cheap to evaluate um the the power of quaternions is that you can combine them to do um you can combine them for composite rotations in a way that is both numerically accurate um and they are faster to composite than any other method or rotation or any other representation of rotation [Music] um so the when it comes the rotation matrices rotation matrices uh transform faster than quaternions um but they don't composite as quickly as quaternions um and so so all of these different um forms of rotation have their own use cases um and so so if you consider Euler angles Euler angles are kind of garbage too because like you have this problem with gimbal lock and all of that stuff um but they're easy like it's easy to just punch in a number like 0 90 0. like you know exactly what that means um so so we use Euler angles for um we use Euler angles for like UI and to easily set up angles or rotations rather um but Euler angles have a lot of other problems uh they they compositing Euler angles is a nightmare um and come by compositing yes I mean combining rotations doing one rotation followed by another rotation matrices transform very quickly um they're very good at transformation but they're stored in nine numbers which is a ridiculous amount of storage space right but they transform very efficiently but they don't composite well at all um access angle is also very useful because axis angle allows you to go for like angles Beyond 360 Degrees you can make this axis very long um and then you get like an angle like the 5 000 or whatever right um and you also get the access immediately out of it which which can be useful in some cases but this one does not composite well either doing composition using axis angles as in this rotation followed by this rotation is actually slow with axis angle um and so the only reason we use quaternions is because they're fast they are very fast at compositing um so if you have some quaternions q p r if you multiply these together you get the same as if you're doing these rotations in succession so you get a single quaternion that just does all of these right so that's the power of quaternions um which is kind of wild at this really annoying difficult representation happens to be the fastest way of doing uh composition um and and also related to compensation is also interpolation um like pretty much all of these are garbage for interpolation but quaternions have very fast interpolation um so again quaternions useful for compositional rotations and interpolation in other words slurp right that's why we use quaternions um even though quaternions are the most confusing most unintuitive uh representation of them all right um okay all right I think we're ready to move on um all right let's add a little divider um knee we have now talked about some some a little bit of abstract algebra um but what if uh oh we have a question uh why is it 360 for degrees um so I think we don't know exactly the historic reason for why this is but I'm pretty sure it's because it's a I think it's called a highly composite number um and composite means that um there are it has many dividers or specifically um it has more divisors divisors than um every number below it and so so 360 is one in this list here um I think it's even more divisible than that um yeah okay here we go it is called a a colossally abundant number apparently um it is also superiorly highly composite number you can divide it by many things that's that's what this means um uh so so there you go that that's a useful number um it's not regardable though um yeah well garble is a whole different Beast altogether um uh okay all right I like if you have an emote for garble it looks like a cult symbol of some sort um all right um so um let's see where do we go next um okay so now I'm going to talk a little bit how I lied to you um in the beginning of our lecture um I lied to you when we were talking about vectors for the first time um yeah I'm sorry I lied um now that we have the perspective of the imaginary plane and the idea of using symbols like abstract symbols that we do Algebra with um we are kind we've kind of already been doing that I just haven't told you because it's kind of hidden and it's implicit um so remember in the beginning of this lecture or in the beginning at the beginning of our whole math class I talked about how we started with a number line right where we have our our numbers negative one negative two one two and so forth and then I said okay if we take this number line and just rotate it and create two perpendicular lines like this um then we get the Cartesian coordinate system where um where you know we we have our our x-axis and the y-axis right um so where we have our y-axis here and then the x-axis here right that was that was kind of how we started this but this is a lie I actually I actually skipped step here that is kind of sneaky that you you actually don't really have to care about for the most part most people don't care about it and don't it doesn't matter um but when we have a vector space like this um just like we did for the imaginary numbers remember how we could write this as one plus zero I um and this actually applies to vectors too in other words we we have a basis vector the x axis here this arrow is our basis for the x coordinate and this Arrow right here is our basis for our Y coordinates right um and so so these two are units like we can call this we can call this X or maybe we can call it a x-hat to clarify that these are normalized um and then we have the the y basis and so when we when we write a vector like um let's let's let's extend it a little further um when we write a vector like this like we do a parenthesis um and we say a number like um like like we have uh the number two and then we have the number uh three this is actually a shorthand we're kind of skipping a lot of steps here we're kind of just we're kind of just showing these numbers um and we pretend that like oh this this is obviously this coordinate here right because we have the uh the x coordinate corresponds to two um and the y coordinate corresponds to three right but we can look at this from a different perspective and that perspective is that what we're really doing here is that we are taking our our basis of x and multiplying it by two and then we're adding the basis of Y and we're multiplying that by three and so there we go and so just like how we could write imaginary numbers using our like invented units we usually we kind of do the same when it comes to vectors uh we we have this um we have this concept of a basis um so we have the the X basis and then we have the Y basis and then these are just the coefficients for each of these species um and so this is really what we mean when we talk about um when we talk about vectors and doing operations on vectors it's just that we kind of hand wave this we kind of just pretend this isn't there right we just say 2 3 and then you just have to know that they correspond to coordinates um and so why why am I talking about this well because when you want to Define operations um this is where this starts becoming interesting um so so let's say uh you want to add two vectors together um so so we we can just do we have a vector here right and then we want to add another Vector on top of that um and so let's pick some numbers we can that distinguishes it so six um uh X hat Plus um seven uh y hat and then if we want to figure out like okay what happens when you add vectors together we can kind of just work this out right um and so what that's going to end up being and if we just treat these as like algebraic symbols like oh we have X and we have y um then this is going to turn out to be um so 2 plus 6. times x hat right and then Plus um so we have three uh three plus seven times the the y-axis basis so that's y hat um and so so when when we want to figure out what happens when you multiply vectors together or or add vectors together or subtract vectors um instead of just like following some sort of predetermined math book of like oh this is how you add vectors we can actually work out the math ourselves like okay well let's let's just Define two vectors this way add them together see what happens and then then we get the rule out of that right like oh we notice that okay if we take a vector and add it to another Vector that means all we're doing is adding the components together and that gives us the coefficients for the for each basis right and so that's kind of cool right like we have we have this um uh we have this new way of looking at vectors that can actually help us determine what certain operations do um and that also naturally kind of kind of begs the question of like what happens when you multiply two vectors because we've been saying all this time that like you cannot multiply vectors it's just not a thing um like you don't multiply vectors uh we just have different types of multiplication like oh we we have the dot product that's one way you can multiply vectors um or we we have the the cross product this is another way you can multiply vectors um and so forth um and the reason for this is precisely because when we try to work out the math for multiplying vectors we actually run into some trouble um and so I'm going to show you what that what that trouble is um I think first we can probably replace this with with actual actual constants to make this a little bit more a little bit more General um so we have a and then we have a b y um now a CX and then d y okay and so this is this is the formula for for adding vectors together right um so okay um so this is a little bit of a different perspective than what we were used to before because before again we just kind of hand weaved it we were just like oh you just do it component wise that's how it works um but now we kind of manually work that out um okay so now the question is what happens if we multiply this because we want to work out what multiplication means um for vectors um okay um so this is going to be a little bit messy so I don't know if you remember how multiplication rules work but we basically need to multiply these two together and then these two together and then add them all up basically um okay uh so so this is gonna be uh a uh a c so far so good these two are just scalars right like two numbers um so we have AC um and then we have x uh hat right X hat um but the other one also had X hat so we actually have X hat squared um okay and then the next one um so this is a um let's see a d um X hat and Y whoops wrong wrong green y hat so these are our bases just remember that um and then Plus we're gonna go through this this is a long long equation um all right and then we have B um times uh d and we have I'm taking a minor shortcut here I hope people who are experienced doing this don't notice uh y hat and squared um okay and and so so now we we end up with this kind of kind of a mess right um because now it's kind of like well okay um so what is what does this even mean um like like what does it mean to square the the basis Vector right like that's kind of confusing and what does it mean to to now multiply these two basis vectors aren't we kind of back to square one because we we don't know um oh what happened to BC uh oh did I skip BC I'm sorry maybe I don't like BC maybe that's it okay so uh b c uh that's a y wrong color white hat I'm sorry um why had uh X okay there we go all right um what was I gonna say um right and and so this is kind of a kind of an unwieldy unwieldy equation where that has like lots of lots of ambiguities because like what does what does it mean to to square the basis Vector um because then then again like what does it mean to multiply two vectors um or like what does it mean to multiply the the X basis by the Y basis um and so here's where we can start adding a little bit more of a custom algebra um we can we can inject one one little one little fascinating rule um so what if what if we Define a new type of algebraic object for this [Music] um like okay if we if we have two um two vectors like this what if we just Define a new quantity that represents the surface area that these two would form together um that represents this area right here like what if we just invent a new type that is this area um and we're going to say that that is the that is the uh the type you get when you multiply two vectors together um like this um and so so this will actually I'm going to skip a few steps now I'm not going to derive it all the way from the start because it becomes kind of um circular um so so this is called we're going to call this a bi-vector and so so we have a the the concept of a number right and then we have a concept of a vector and then we're going to add a new concept called the bi-vector and that is going to represent this area right here um so so if we multiply these two vectors together we get a bi Vector that is this area um and and so so what we're just going to say that X hat times y hat represents that area and if you remember this is where we're going to introduce the wedge product again so if we do the wedge product between these two um then we get the the area of of this region right we've talked about the wedge product before um it is uh somewhere here uh where's our here it is uh where if you have two 2D vectors and this is how you calculate the wedge product um and so so this is the formula for the wedge product in 2D in 3D um it is actually equivalent to the cross product which is which I've lost uh here it is and this would be the wedge product in 3D and so so there are a few things you need to note here by vectors in 3D have three components um they have X and they have y and they have Z but bi vectors in 2D just have one component um which might be a little bit confusing but if you again consider the area that they represent um that is the bifector um so we're just going to say that when you multiply two vectors together um that is going to be um The Wedge product between those two um and so if we know that the that's going to be the area between two vectors um then we can kind of already know that okay what if we take a vector and we Square it what is the area that that the span between two vectors that are exactly the same crates what's that area well the area of two vectors pointing the same direction if you have a vector like this and a vector like this um you can see that the the area kind of shrinks and the more similar they are the closer it's going to get to zero in other words if we square a basis Vector we get zero um at least using the the um the wedge product um okay and so skipping a few steps I'm going to skip ahead a little bit now I'm not going to work it out all the way from the ground up um multiplying two vectors let's say that we have a vector I don't know if we should call it a because we already had a component there but pretend this is a new thing but multiplying two vectors together A and B we can actually Define that as the dot product between a and b Plus the wedge product between a and b okay so this is kind of the the core of geometric algebra this is called um the geometric product and this is the default product when working in geometric algebra um um I suppose there's a very obvious algebraic extensions of this with tri vectors uh yes there is um so so this is the um geometric product between two vectors um and so so what's going to end up happening is that we can work out a bunch of algebraic rules um so that this will basically boil down to to the geometric product um so it's basically just going to be the the dot products plus the wedge product um and so um yeah oh sorry yeah the squaring it doesn't become zero it becomes a one uh sorry I got that wrong uh squaring this one uh it becomes one because we can look back to the geometric product now like what happens if you do do a a times a that's a squared right um whoops again I haven't I haven't taught this before uh and so I'm a little a little rusty um so a times a would be uh a DOT a wrong color a DOT a plus um a wedge a um and we know that the the wedge product between um vectors pointing the same direction is zero um and the dot products between two vectors pointing the same direction is the squared magnitude right um and so if it's the squared magnitude in other words the length squared if these two are normalized then it's just going to be one right because the the squared magnitude is one and so so that's why when we square a vector we actually just get one um okay so so a a hat squared equals one okay um and so so we can kind of see what happens here right um if we have AC times x squared um then let's move that uh well x squared is just one and so so basically this just boils down to AC um and then Plus uh a d um X and Y right um and then Plus b c uh y uh X and then Plus um that's the wrong B color sorry about that um plus b d and again we have a square so y hat squared is 1. um and so now if we if we rearrange this a little bit we do some some clever we do some clever moves whoops whoops I'm being too clever um we just move this over here um this is the dot product right um like you can see that we're taking a the x value multiplying it by c um and then we add the the Y values multiplied together so B times D so this is the dot product right um and then we have the rest of it here um and so so what's happening here is that we have X and Y and then Y and X um and if we look at the geometric product how we deal with these two um it's the dot product plus the wedge product for these basis Vector vectors um and the um and the the dot product between these two is zero because they're perpendicular so the dot product between this one and this one is just zero because that's that's how the dot product works if they're perpendicular they're zero um so so all we're left with is the wedge product so so we get um X hat wedge y um and we also know that the wedge product is anti-communitive in other words a wedge B um is equal to negative B uh wedge a right um and so since we know that all that's left is the wedge product for these two we can actually apply this rule to to swap these so we can we can if we just move these just shuffle them around so that we have X Y here instead and then we multiply by negative one because it's again anti-communitive um so then we get Negative there and then we can factor out this right we can factor out the X Y um and so now we can we can move this over here and then we got got a parenthesis um and here we're going to get a d oops this is going to get complicated I'm sorry it all got very algebraic uh but that's kind of the nature of this so I hope it's somewhat understandable at least it's very abstract that's why I saved this for last because it's it's again it's it's it's abstract so now we can remove that part and that's that's kind of neat um so now we just factored that out um and so there you go um and hopefully you can see how this relates to uh the dot product and the wedge product um because the if you look at ad minus BC here that is a so the X component of the first one times the Y component of the second one minus the Y component of the first vector and the um times the the X component of the second vector and that is exactly what we had for our wedge product up here that's what we're doing here um and so and so this is what happens when you multiply two vectors however um now we've run into a very strange place because now we have this construct where this is just a number right like this is just a real number like like six or whatever um and this is a bi Vector because we have this thing where we multiply these uh basis components together um and so this is where it becomes useful to try to think of um something called a multi-vector and this is kind of the the mother of all vectors um and so so this this is the this is the final boss I hope you're I hope you hope you're ready um and so when we think about multi-vectors then what that means is that we can Define this giant Vector that has all of the bases that we might need in our coordinate system so in a 2d coordinate system then the full extent of it is that we have a basis so I'm going to do that in curly brackets we have a basis of one so these are our real numbers right um and then we have our x-axis right so this is our our x-axis uh we have our y-axis and we have our I guess we could go for z-axis I don't know we can do both actually we can stay to stick to 2D for now um and then we have the uh basis by vector so we multiply these two together and we get this bi vector and that represents the the area remember the the area of this uh is a construct called a bifector that is equal to these two multiplied together That's the basis by Vector for 2D space um and then there's um yeah that that's it there we go um so this is the full multi-vector of two-dimensional space um and so so when we have a vector we only have values in these two right if we have a normal just a straight up positional Vector like just just a just the regular vectors we've been using all throughout this entire Math course we've been sticking to these two right um and so so what that means is that the the other values are just zero um and then we just have some values here right um and that means that we interpret this as a positional vector um but what's weird is that when we multiply vectors together um just like we saw here using the geometric products we now have a real component and a bi-vector component and so when we multiply two vectors together we all of a sudden have like some number here like five and it's zero for the basis vectors and then we have some number for the basis bi-vector um so so this is kind of the full multi-vector that contains all of these different bases um and this also of course extends to 3D um and so we're gonna we're gonna gonna do our regular old old axis I also have no idea how we're doing on time but we're almost done with this um what okay so uh we got our our y hat right that's our y-axis we got our x-axis and we got our z-axis okay um and and just just a reminder like I I remember that I said that I lied to you earlier and that's because I I kind of pretended the x-axis is the same thing as the real number line but when we're talking about geometric algebra it's actually really important to make a distinction between them because these two bases are not the same thing um the the real number line is actually perpendicular and separate from uh the the x-axis and the y-axis so that's why I said that I kind of cheekily lied to you um although not really but you know um and so the real numbers exists independently of our Vector representation um all right okay um and so for 3D so so this is the the 2D multi-vector um so for 3D we actually have um a little bit more so for 3D um we have our real numbers that's a basis of just the number one uh and then we have our x-axis uh we have our y-axis we have our z-axis and here's where it gets a little bit interesting and here's where people will fight over how to how to do these uh basis by vectors but remember the bi-vectors represent an oriented area and this is a little bit of a bit of an abstract concept it took me a very long time to wrap my head around this but I think that the easiest way I can explain this is that when you have a normal vector um the position of this Vector is kind of defined using projections if you project this to the y-axis or you project it to the to the z-axis um or or the x-axis um we kind of get the coordinate of this this object right um it's a little bit a little bit hard to to draw these um so so all this is is kind of like we're taking a 3D Point projecting it into one D and then we get the distance here per axis [Music] um now imagine doing the same thing with a shape or an area so let's say that we we draw some sort of area here like a like a plane right with some orientation um just like we projected a point we can actually project this area like what would the shadow of this shape be um against this plane here the plane formed by the Y and Z axis and this projected area that we get here it will most likely be kind of a slim rectangle right um I'm going to draw it in red um so so this would be the projected area for this plane right uh we can project it downwards as well so if we project it down onto the the plane here uh that would kind of be the the shadow of that plane here as well right um and then we can project it against the z-axis or the Z plane which is this plane right here and this is going to be like a very thin one it might actually be exactly zero so that's going to be a very very thin Shadow projection there right um Okay so a bi vector is expressed like just like a vector is expressed using projected distances along each axis a by Vector is expressed using the area of each of these regions and so so you can actually you can express a bi Vector using a vector 3 like you just you just use that as a container to to specify all of these areas right um so we we have the area here the area X um an area Z and area y um so we kind of split it up into its components just like we did for um for vectors so we have area X um and then we have uh area y then we have area Z but we need to remember that this is not the same thing as a position Vector again this is an oriented area and what we mean by oriented is that it can actually point in both directions if you remember the normal Vector um the these areas can be signed and so that the normal of this plane can actually point in both directions um and they are not equal so we can actually mirror This Plane if we want to um and so so this is what a bi Vector is um and I don't know how much I separated this to a separate layer but um and so so we're kind of projecting these onto the planes here I hope that analogy made sense with the Shadows um this concept is really abstract again it took me several days to get this um so so don't worry if you don't get this immediately um Okay so we have our basis vectors and then we have our areas our oriented areas here and these are our basis by vectors um and so this is um X1 multiplied by y hat so this is the same bi-vector we had in 2D right but then for for 3D we have two more bases by vectors we have this plane right here and this plane is uh y hat times Z hat and then finally we have the bottom plane here um and the bottom plane is the the basis by vector um from Z hat and yes it starts with a z if you read a blog post that starts with X here they are objectively wrong and you should never ever do x z here so so those people um okay and so these are our basis by vectors um so um in our 3D um in our 3D multi-vector these are the basis by vectors we have to work with right and the Order of these three is kind of Up For Debate um geometric algebra especially in game development is very much in its infancy we're kind of starting to explore this at this point but it's not something that's been established at all um and so a lot of these things haven't been worked out like what order these should be in um my opinion is that um we we should start with uh YZ that y z should be the first one um it doesn't really matter which order you write them in as long as you're consistent within your application but if you want your application to communicate with other things it might be important to get this right um yeah so so YZ and then z x um and then finally the one that we have in the 2D system which is X Y and there we go um I need to scoot this a little bit I don't know layers um okay and so now we can also add a third one uh which is we're kind of taking the same idea and extending it one step further and this is where we get the volume of this um and that is called a basis tri-vector which is kind of rarely used um so the the basis tri-vector is um of course X y Z um and there we go this is the full multi-vector for 3D geometric algebra um and so so there we go it's a bit of a mouthful um and I need to organize my notes without moving everything to to hell and back okay this is geometric algebra look we we actually cover geometric algebra um and now we can we can like drop some cool facts about geometric algebra um here's here's um it's 4 pm on a Friday yes uh I'm gonna go for a few more minutes I hope you don't have to run off to you to anywhere um there are a few more things I want to talk about because I'm excited about this and it's interesting um but but if you really have to like go pick up your kid and they're like screaming at kindergarten and they really want you then feel free to leave again this is more of an optional last thing um and so um the um wait are you criticizing my diagram are you not liking this um yeah well you're wrong um okay and so so one thing that's pretty cool about this is that this multi-vector like you you can write a vector containing all of these numbers like you write arbitrary numbers in each of these um so what's kind of cool about this is that this geometric algebra like we've kind of like sort of invented this whole separate algebraic system um what you get if you take uh this one like the the real numbers the real number line and if you take the um the X Y plane right here uh this if you use only these two components that's complex numbers um so just straight up using these and these you have the same definition as complex numbers um and and and that's kind of wild like if you if you have X hat um and Y hat and you square this you have negative one and this is exactly the definition of imaginary numbers um and so you actually have the behavior of imaginary numbers can be directly encoded in this type of format using bi-vectors and so the imaginary number we could also just call that the uh the basis by vector um and that's kind of weird um and pretty cool and the same thing actually goes for quaternions uh if you take the the real part here so we have the the real numbers and all these three um this is a quaternion usually you would call these i j and k but in geometric algebra they're just basis by vectors right because all of these are square to negative one and so so this is actually encapsulated the entire behavior of quaternions um and then what about vectors well vectors is just these three right like if we just use these we have a regular old standard vectors um and so this is just a way where we can sort of generalize a lot of these Concepts uh into one framework um that makes it very consistent and portable and actually scalable to any dimension um yeah and I think that that's a that's a pretty interesting fact that just because you start defining this new geometric concept of a bifector um all of a sudden you you actually encapsulate the a lot of the things we already talked about like imaginary numbers and vectors in 3D space and quaternions like we just do that right um and so so what a quaternion really is is it is a construct that has a real number the real number line and it has uh three uh types of imaginary units uh there are three separate imaginary units um but so so that's part of quaternions and the the whole concept of a quaternion is that the three basis bi-vectors actually Define a plane right because again a bi-vector is an oriented area it has an orientation and the magnitude is the area of that plane um and then we have the the real part of a quaternion um then what what the quaternion does is that it encodes trigonometric properties and the real part and the magnitude of the basis by vectors or or the bi-vector part and then it can basically reconstruct a rotation around that plane using that information and the way that it's algebraically set up just so happens to be in a way where if we multiply quaternions together it's like taking uh one rotation and then doing the other one um when you're doing uh quaternions but expressing them using a geometric algebra they're usually called rotors so you're going to find this term if you're searching for geometric algebra and rotations then rotors are going to come up as the rotors are basically a um a a multi-vector that contains the real part and the bifector parts and then using those we can multiply them together to kind of Stack rotations um and so so that's that's how you get um quaternions from geometric algebra um all right there we go that was everything I just had to word vomit it's a lot to talk about and I hope it wasn't super duper confusing you can sort of think of this as an introduction to geometric algebra um yeah any questions was that like 100 super duper clear do you feel like you have 100 grasp of geometric algebra at this point um I'm not expecting you to I I haven't been had I haven't had any water or anything to drink for like the past hour I don't have enough grasp to ask questions yeah that is expected um usually you kind of have to read up on this a lot to to kind of wrap your head around the concept it's usually pretty difficult um yeah it's also kind of esoteric uh right now the geometric algebra is like very very slowly making its way into game development uh the uh mostly the idea of um geometric algebra has mostly been used in people making like four-dimensional games because geometrical geometric algebra um actually extends to any Dimensions so it's a very general concept um yeah um and it's actually kind of it's actually kind of interesting if you consider the number of components for for each of these uh constructs for the bi-vectors and tri vectors um then does 40 games exist uh yes someone is making a 4D golfing game uh and then there's another game called miyagakure I think which is a puzzle exploration game uh very experimental stuff um yeah um I forget all of the the four dimensional games um but I think the the biggest thing about um geometric algebra in in games uh is that you can basically replace quaternions with rotors um and it's it's just the same basically um it like like quaternions and rotors are just different ways of describing the same thing the math turns out to be exactly the same uh and there there's not like any um yeah you don't actually um get there's no difference apart from the perspective that you're viewing them okay so I think this is one of the games uh yeah yeah this one so this is a four-dimensional game um I don't know if they use geometric algebra for this one um but it's a uh it's a puzzle game where you can um basically shift the world through the four-dimensional space uh or through the the form the fourth dimension which is an axis perpendicular to um the the other axes right and it's very hard to wrap your head around about what the is going on when you're doing like 4D Transformations like this um but it's it is a game that has Concepts from 4D um and so there you go that's a puzzle game um that's a 4D game uh and then there is a uh uh 4D golf game I forget what it's called um I think it's this one um yeah so this is from from a fellow YouTuber code parade that they're making this 4D golf game um and so you can kind of you you kind of get this projection of the 4D space into 3D um and so you can kind of warp and view view things from different angles right um and so so when you're making a game like this the the way that you represent geometry and angles and literally everything gets really complicated um as you can see it's very very hard to even see what's going on it is it is very trippy yeah um because our brains are not very good at interpreting 4D space um but yeah so so 40 games exist they are rare and it's mostly people who are really excited to do some incredibly esoteric math um okay um yeah so 40 games imagine that um okay we didn't super dive into the black box of quaternions uh we barely scratched the surface we've just like explored imaginary numbers um and so so quaternions um uh so quaternions they are uh kind of a they encode angle axis effectively it's a special encoding of angle axis so if you look at the the quaternions the the ijk here those are equivalent to the uh by vectors here the basis bi-vectors so each of these Square to negative one just like imaginary numbers um and they have some fascinating properties and the the whole thing that they're useful for is rotation um and rotation is done by taking your quaternion multiplying it by your vector and then multiplying it by the inverse of that quaternion or the conjugate which is a little bit faster to compute and this is called a sandwich product which is going to come up a lot if you're reading about geometric algebra or um uh well geometric algebra or quaternions um yeah and and there for mathematical reasons they composite very well in other words rotating something by one quaternion and then another quaternion is the same thing as multiplying those quaternions first and then rotating the vector by that quaternion um and so and so yeah there are many different ways you can you can try to interpret this I can share this with you if you want um if you want to read up on quaternions there you go um these are these are my own notes the picture is not my own but um but yeah uh why is there a garble taking over um okay all right I think I think that that is all I wanted to talk about I think um do you have any questions anything else you want me to chat about while you have me because this is the final day I am I am leaving soon um well very soon uh do you have any thoughts or questions about the whole course and lecture and all of that stuff it is the end of your lectures um yep no more math you no longer have to suffer through all of this um which is the screen full of full of numbers and symbols um uh um will you still be able to answer some questions after this uh depends on what type of questions and how long after uh this is the end of my time with future games here and so after after the lecture it's not gonna I'm not going to be on the clock so I'm not going to be available for guidance or whatever um answer questions like tomorrow or next week I usually vaguely hang around and discard so sometimes I will uh but I'm not gonna get paid to do it so but usually I will still exist and and do a little bit of a little bit of answering but don't expect me to answer quickly uh because I'm going to be doing other things uh aren't you going to teach us shaders in December oh yeah I mean I'm going to do your Shader course as well but now we're not doing shaders right now so now this is the end of the math course so [Music] um can we pay you in candy uh not really no I'm sorry it doesn't work that way um okay well if there are no no further questions um then I guess I guess that that's it now you know quaternions um yes all of these streams are going to be on my channel so if you want to re-watch anything you're very welcome to do that um yeah um if you I guess oh here here's a way you can pay me if you can crowdsource timestamps for every topic on the YouTube video because it takes a long time for me to go through every video to find like okay this is where I start talking about quaternions this is where I start talking about the first assignment and so on so if you want to crowdsource the timestamps that I should put in the comments of the YouTube video that that would be valuable but it's kind of tedious and boring um um okay um yeah thanks for having us it's been informative oh yeah no no worries um are you allowed to advertise your products um well I mean technically I've gone overtime and I'm outside of the lecture hours so I guess I could um but I do you want me to or are you asking if I've already broken the law by talking about shapes or or are you just curious about shapes or um thank you for teaching us no no worries uh I I I'm I'm happy to teach math um and I hope I hope it'll be useful um I know this course is very intense if you are if you're pretty new to math and um a lot of these things are like completely new to you or you forgot everything from like high school um we've basically been speedrunning math from like first grade to late High School um in like six days um so if you feel like this is overwhelming and there's a lot to learn um that's normal it's totally okay to feel like this is overwhelming and then on top of that there's everything related to like programming and data structures and all of that stuff that I'm kind of just like presuming that you know um so just keep in mind that this can be overwhelming and it will be for for many people um yeah um but yeah I hope this has been this has been valuable um I can also show a little bit of shapes if you want to see it um as part of not the course but just as a human being sitting in front of your computer or on in your computer um if you're interested to see what shapes is uh I've been talking about it a lot throughout this lecture I guess or yeah lecture series um learn more math in two weeks than I did in 12 years of school that is that sounds great I'm so happy to hear that I'm glad I'm glad it's been it's been that useful to you um [Music] um oh okay um never wrapped my brain around most of this in high school because I never did anything practical yeah yeah that's usually the problem I have with it as well it's usually like why why am I gonna need this I have to go garbled everything started to fall in place that's good I'm so happy where garble could could do that for you um I still have to work out the algebraic properties of um garble um so I'll get back to you once I know what the definition of what garble is um um okay I should save this um I'm gonna stick around for a little bit longer um you wanted to see shapes so I can show you shapes if you want to I'm just going to export this image um this is taking a while to load come on come on save for web they believe in you excuse me well I guess I can start using shapes while Photoshop is thinking um where do I [Music] do you feel more confident to hold an online lecture rather than inside a classroom I I hate using shitty School computers where the monitor is like 30 FPS as shitty color and the mouse is like lagging and the keyboard is bad and I don't have my shortcuts I don't have my applications I don't have anything that I'm used to having and it feels like I'm using like some some sort of alien workstation um I hate that and so I love to do remote teaching because I have everything set up exactly the way that I want it to be and so so yes I love doing it uh remote so um yeah and and so so doing it like on site is going to be a strictly worse experience except for interpersonal stuff like for hanging out for the like uh mingling and getting to know each other and reading the tone of questions like anything like interpersonal is easier when you're on site but um yeah but the the teaching itself is much easier um remote for me um um okay how did Photoshop manage to oh yeah there we go cool uh this is a very large file it's 11 megabyte would you also bring your cats if you were allowed into a classroom um I don't think I'm allowed but let's say if I was allowed uh maybe the problem is that they they would have to get used to litter boxes in a new location um maybe if if the classroom had a litter box then yes I would do that um the uh yeah I think that would be the biggest issue otherwise I think I would bring them um because I've gone for walks with the kittens and so um they they know what it's like to not be at home at least uh okay so this is just gonna take ages again uh but let's I can show you shapes let's let's let's talk a little bit about sheeps why not um I'm gonna create a new scene um oh I have my math library and everything here hell yeah now I'm now I'm fully at my my full capacity finally um let's fix the the lighting this is a bad lighting situation there we go all right [Music] um yeah what do we want to do with shapes what do we want to draw um um okay just to show a basic thing um if we garble um you know should we draw with garble okay we should do we work out the equation for a garble first okay um oh I flipped it uh what just happened in chat or in in the discard that is unreadable why is this not working oh because I there we go okay um I think I think we can just just do this with um just trig functions right the uh it might take a while I don't want to get stuck on that let's look at shapes instead it's more fun um wait why is my formatting not working oh maybe because it opened in the same writer uh yes shapes will go on sale very soon I think um shapes is going to be part of a Humble Bundle um and so it's gonna it's gonna go on there so yes it's gonna be on sale um okay uh and so here here let's let's do some shapes um the my favorite way of drawing shapes is using a thing called the immediate mode shape bar which is kind of similar to Andre gizmos but better um so we have a function called draw shapes and then we set up a new draw command um to draw in our camera and here we can draw whatever we want um so we can maybe do draw. Matrix equals transform a local World Matrix this you recognize um we did this in gizmos as well and then what do we what do we want to draw uh maybe we want to draw a um maybe we want to draw a ring uh we want to draw it at zero uh maybe we want to draw it with a uh oh right the the rotation I guess we can just do the default rotation uh and then we'd set a radius to one and we need a thickness so point of four something like that maybe um and so then what's this let's also Mark this as execute and edit mode so that we can see it in or sorry execute always that makes it visible in editor Empire and there we go look at this shape um and so in shapes you can specify thickness and it actually has anti-aliasing there's no shitty pixelated garbage things that you usually get with like gizmos or handles or whatever um so this one actually looks kind of clean and nice right um so so what do we what do we want to draw with this um maybe we want to draw a line from Vector 3.0 to a new vector um excuse me angle to Direction and maybe we can do a Time dot real time since startup uh okay now we should have a no should have a spinning spinning line uh there we go always refresh so this is a line it has a rounded end cap um we can also make it look different we can make a a um um I don't know we can make a look whatever we want we can also fill this circle so maybe maybe we want to have a little little bit of a background color um so we could do just pass a color in here um and then there's going to be a disc with no thickness I think we can also skip the rotation for both of these um so this is a fill this is the Border um so recompile now now we're going to fill the background and so we're we're starting to create a thing with it right um and so the you can this is kind of what the library is and it also works in 3D so you can you can draw things in whatever whatever space you want and and however you want to draw it um all of my all of my videos are are made using using shapes so we could draw like polylines and stuff as well um yeah lots of things you can do with this but this is basically the uh what the API looks like um you cannot draw in 4D no um um then it has a bunch of different functions um you can you can draw rounded rectangles you can do dashed circles it also has a component based API so you can make a so let's say we want to draw an arc um so we can increase the radius change the thickness uh maybe we want this one to have rounded caps uh maybe we want to have a dashed Arc where we set the number of dashes um to some some value maybe one rounded dashes um so there we go uh that maybe we want to change the thickness a little bit again um maybe we want to offset the dashes so we can animate this over time if we want to we can um yeah lots of things we can do using shapes um just has a bunch of features like this um you can set the the end angle the start angle um it's very flexible and so anytime you want to do vector graphics in unity um then there you go this is the way you can use um yes this is basically vector graphics uh there is there's no aliasing because I made the shaders so that they don't have aliasing um yeah I have anti-aliasing baked into the into the shaders themselves um and so yeah and so and so this entire this entire uh concept that this whole whole way of working um this is how I made my bezier card video um I don't know if the bezier curve video actually runs anymore because I have changed a lot of things since then um but like this this whole video is also made using shapes and it's all animated in unity um and and drawn using shapes and I have this like custom animation tool that I have for for doing these types of things so in this case it shows you how to get the bounding box of the bezier curve which you can do if you analyze the derivatives which is kind of kind of neat and then you find these extrema um yeah and then showcasing the derivative and whatnot all of this is drawn in shapes um and it's animated in code for the most part um and yeah so so this is all just like scene view Shenanigans um it's all all drawn in real time um so I'm doing doing a lot of vector graphic style drawing assembly to animate and do all of these things um okay oh so that's shapes you can draw draw a vector vector yeah here's my here's my outro see it turned 3D isn't that neat um the 3D capabilities of shapes as in drawing like volumetric shapes is a little bit more limited um and that's where you that's where you have a little bit more aliasing because it's there's just no way to do anti-aliasing for 3D shapes that's that doesn't like tie into the render pipeline in a way that's going to be a nightmare um yeah um is it bad if you run a lot of this every um [Music] so I mean it's not gonna be super expensive um but it but it all depends on how you set it up um oh I broke the code for this oh no they're slightly borked um but yeah the um you can definitely use this for AI but yes you have to run it every every frame especially if you use the at least if you use the immediate mode you can always use the components themselves if you want to but beautiful I like how we have a billboarded polyline for for the credits as if I needed it to be Bill burden um okay um sheeps so spline spline videos the one that I'm currently working on it's a like all of this is also still animated in unity just there there's no I don't have any pre-rendered animations um it's all real time ah this has taken so long to make I need to release this soon I spent so so so so long on this like a ridiculous amount of time um and then I got burnt out and I still haven't fully recovered from it and so it's like uh I'm like I'm like at the end of this video I'm like almost done I just have like two or three things I need to do before I can call this down um but uh almost there um salad is the best contributor because he is large that's true yeah um and so all of these all these animations are set up in code so um you can actually see some of the easing functions at the bottom here um we talked about easing functions today right if you look at the the three functions here you can see that there's like some cascading curves there are four of them one after the other um that's triggering this animation here that's each of these four and that's animating out over here um and and the whole the whole video editor is fully uh predetermined like all of this is uh directly set up where every point in time has a specific value for everything that happens and so I don't have to simulate anything ever I can jump to any point in time and everything knows what state it should be in um and so and so it's a it's a very nice way of setting things up because I can I can freely change time however I want it's not like it takes time to reverse um I can literally set the playback rates to negative one um and I'm gonna play the entire video backwards right because because I don't have a concept of like simulating anything um yes everything is dynamic there is nothing that is like yeah there's no Dynamic systems in this um although I have been wanting to add some Dynamic systems um because there are a few things that are hard to do like this um but um but yeah continuity would you say that it has cut down on time or increased like having code based animations and stuff like that um I mean I wouldn't be able to do these things without code-based animations uh because uh all of these have to be mathematically accurate like if someone told me oh just just freehand the uh curvature curve for this hermite spline I wouldn't be able to do this right it has to be code based um but uh but in terms of just the animations apart from the drawing um it would maybe work but I feel like it would be tedious I started doing a workflow like that at some point uh but the problem is that a lot of video editors and animation tools are not made for uh Ripple editing um in other words if I want to I want to make one animation a little bit longer in most video editors um you have to like select everything to the right and then move it a little bit or if they have built-in support for ripple editing you can use that but the um the way that I set up my animation tools everything is Ripple added by default you yeah I can insert an animation anywhere and I don't have to care about everything that comes after or anything that comes before um every animation I can just insert something and everything ahead is just going to shift automatically um and so it makes it very um makes it very nice in that way um yeah um I can show you what the animation code looks like uh if you're curious oh this might be the the most horrible of them all so let's open the horrible one production code right um I have a million functions here um so here are separate animations so I have animations in every every script um and so this is what my animation looks like um I like label a section just to make it easier to navigate and then it's basically I say show this value animated from 0 to 1 over 0.6 seconds with this easing function and then wait for that to finish then um animate show curve index 3 over 0.6 seconds with an easing function out three to one show means animate to one and then I pause for one second and then I show a cascading range of points labels so Cascade means that I show several things one after the other and then I just give it a range from index 7 to 13 I use an easing function on all of those and then it's just kind of this is the animation this is the animation data for the entire video um and so uh the the timeline that you see down here this timeline um is literally just um just for previewing those animations so I don't do the animations in the timeline that's just for previewing um and so and so the um so like for example the point labels here um so Point labels is something that I show a lot so you can see that these points here they appear one after the other right uh so this is a cascading animation so that's just a helper function I have to do this like reveal of many things one after the other um and I do that a lot like in many different uh places um and so so the um here's an example another animation where I reveal one thing after the other as you can see here just doing like the lines and the points appearing um also set up the same way just do this cascading animation um and so forth um yeah oh I should release this video I've been working on it for way too long um goodness okay anyway um are there any other last final questions before I before I go I'm starting to get I'm starting to get my streaming headache as usual um so I'm gonna have to stop streaming pretty soon um psychwood programming is actually for like making tools to help you do what you want easier uh yeah quite literally the the whole um yeah all of this is very much just because I I had to I needed to do code based animations and there was no like existing tool that was good for me um and everyone was always like oh you should use three blue one rounds editor and I'm like no I don't want to use python and also mine is real time three blue one Browns requires rendering that I I want real-time because I'm a game developer and so I made my own editor so so here we are um uh yeah uh okay I want to ask what app used for taking notes oh um notion uh it's the same one I used for everything I sent you so I've been using notion which is useful I use it for everything I have a lot of notes on many different splines notes on on math notation notes on trajectories um a lot of notes on trajectories uh yeah good quite quite a lot um outside my notes for for DND for our DND campaign also important to have um I'm gonna have some role play notes and combat notes for things to remember my my reckless casting but I also had a DND it was also good to remember um good things I just have lots of notes and obviously the notes we had for this course um so so the um all the lectures are here also through notion uh not all notes are available some of them are just personal um and so some of them are available and I link them um but not all not not all given the tips on how to repeat everything you've lectured so far um I honestly don't really know apart from like either re-watching if you feel like you've forgotten a lot um or if you didn't finish the assignments you could do some of those assignments um you could also of course do um you could also of course just take other classes like I know three blue one brown has a linear algebra series you can watch that if you want to brush up on that um yeah [Music] um okay I wonder if Photoshop is done saving the image I think it might be um oh yeah there we go all right um thank you and my brain is also mush huh we covered a lot we did it you are now prepared for the world um any other questions lady last thoughts how's YouTube chat how are you doing YouTube sorry I'm not paying too much attention uh to your your your chat excuse me um all right um I guess we're good no more questions um can you share the math scribbles uh yes I'm not sure if I should post it publicly I'm I'm conflicted on that because I've had a lot of people ask me to make a proper poster out of this um and so I've been considering doing that and like putting up a story where people can buy a clean version of this like an actual poster um but if I but if I release this publicly what if someone just just takes it and then I'm not going to get my capitalism money from them buying the poster if they just steal the high resolution version of these notes I don't know I don't know so so I need to I I don't know if I want to want to publicly release it but I think if I if I do a proper cleaned up version of this then I think it would actually look substantially cleaner than the absolute chaos that this is so maybe it doesn't matter maybe it's okay if people print the shitty version um and nft posting um I will not be able to do it before Christmas I have too many things ahead um but I'm already stressed about unfortunately so um um okay but yeah I should share this publicly um I will I will do that use AI to upscale it oh God um okay I have to cut the string before the four hour mark and we are almost there so this is probably a good way to stop a good good place to stop um then um I guess that's it um if you want the last bits of kittens Thor is in the Box right there that star and tulsar and then we have the kittens they're they're in in each Goblet of that tree we have toast in the top and then and then salad underneath so say goodbye to the kittens um thank you thank you all for for joining the math course uh again hope it was good hope it was useful and for any other like future game students outside of uh fg22 I hope you got some new information uh they that you found uh useful um the all of these are gonna stay on YouTube so you can just go to my YouTube if you want to re-watch these um otherwise thank you so much for for having me uh it was fun uh and I'm sorry if I went too fast for things and I'm sorry if I panned the camera too much in in Photoshop I know some people get annoyed by that um but yeah all right everyone thanks thanks FG uh 22 you've been you've been great uh and I will see you all on the during the Shader course um and and otherwise I'm just gonna hover around a little bit and discard every now and then uh but but yeah bye everyone good luck with all of your future assignments and future games see I did a pun um all right bye everyone
Info
Channel: Freya Holmér
Views: 124,654
Rating: undefined out of 5
Keywords: Acegikmo, Freya Holmér, Freya, Holmér, Twitch, Unity, Unity3d, math, vectors, dot product, scalars, numbers, mathematics
Id: Pku6WAs1fF8
Channel Id: undefined
Length: 227min 20sec (13640 seconds)
Published: Fri Nov 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.