Intro to Graphics 02 - Math Background

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so this is the second lecture and i'd like to start uh my courses relatively slowly so we kind of start a little slow and then you know we pick up speed a little bit so last lecture that was about the introduction to computer graphics what is computer graphics that is very light and today it's going to be relatively light as well the stuff that we're going to cover is going to be basically linear algebra right i think we're studying all right so our topic today is just some basic math background and this corresponds to the chapter two of our book but i am not planning to cover the entire chapter too chapter two is actually quite extensive it's talking about all sorts of math that is relevant to all sorts of graphics related stuff the part that i'm going to be covering is going to be things that we're going to need like now right away and then as we need more stuff i'm gonna talk about that that part as well right so this is a this is not a full extensive lecture regarding chapter two so chapter two involves a lot more the part that i'm actually going to concentrate on today is going to be over here the vectors and i'm going to just briefly talk about matrices as well um and the way that i want to talk about vectors is i'm not going to tell you everything to know about vectors right i'm going to talk about the the basic things about vectors um you know you guys have taken linear algebra so you should be familiar with that but this is going to be a sort of refresher but beyond that i would like to give an intuition of a vector beyond its its mathematical description that's the whole goal of this particular lecture so as always feel free to interrupt me at any time um i'll go through this probably is going to be a relatively short lecture uh our upcoming lectures are going to be uh more uh beefy in terms of content right okay so let's talk about vectors so what's a vector a vector could be can it be 1d sure so a 1d vector would be a a scalar right just some scalar value i call it x here it's just some weird notation um it could be 2d if it's 2d i'm going to have two scalars let's call them x and y it's a factor with two scalars in 2d right in 3d a vector will have three components and fourth is going to have four components why we're looking at 4d because we are actually interested in 4d computer graphics and we'll get there we'll cover that stuff don't worry about that uh and a vector in general can be andy right could be could be defined in an n-dimensional space in which case it's going to have n components um and these those vectors are used in computer graphics but mostly in computer graphics the stuff that we're going to be interested in are going to be right over here right so 2d 3d and 4d those are going to be the the things that we will very very frequently use in various computer graphics algorithms and the vectors um they are used a lot in certain special cases so they're not extensively used everywhere in graphics but they're they definitely have place uh places where they're very very important so that's the stuff that uh we're going to be mostly dealing with are going to be these these three um and of course we're oftentimes related in 3d graphics so this this 3d one is going to be the the most important one all right um so but typically when we when we're writing vectors we prefer using this this uh column notation right and instead of this this row notation so this is a there's a column vector over here and this is a row vector over here and and this is the the notation that we want to use but you know sometimes when you're writing some text it doesn't quite look nice because it's a column sort of sticking out of the line um so we want to be able to write it this way so all we need to do is we just take this this vector and we flip it over we transpose it right so this vector is equivalent to this vector transpose right so whenever i'm going to be writing vectors in row format you'll you'll you'll see this transpose notation here that means it's actually a vector like this but written horizontally sounds good column vector is the the step that we pretty much always use in graphics so the question is all right a vector is three values three scalar values what does that really mean um well it can mean a position in space in three space x y and z coordinates of something it can be a position it can also mean something actually very different but well maybe i should say very different different but related that is direction direction with length and these are actually two different things um it's important for you to understand them as two different things but at the same time they're actually very closely related one of them defines a direction with some magnitude some length the other one is just a position in space so let's say that i um gave you a vector right i said you know that my vector is five seven three right it could mean a position or a direction let's say that it's a position all right and i tell you okay my vector value is five seven three so you know what what that position is right fairly easy i'm telling you what it is so you can you know what can you really well what is five seven and three i mean all right we need to have some units we can't just say numbers all right let's say that i have units all right 5 meters 7 meters 3 meters all right this metric system makes too much sense we don't like it let's move on to something that makes less sense uh let's call it units five units seven units three units whatever units we want to use could be some generic units could be whatever you would like to use so now that i've given you these units you know what a unit is you know what that position is right maybe no oh let's see not that easy actually because um you know first of all i don't want to write these units let's go get rid of the units all right i'm going to write like this so when i say 5 7 3 i mean 5 is 7 units 3 units whatever to be able to understand what this means i need to know these x y and z directions right what is the x direction where is this all right so let's say x is this way right this is x if x is there y is over here and z is up there all right so i have some some direction i i define this direction so this is x and this is y and i have z right i'm not sure if it is right-handed left-handed i'm seeing myself mirrored so i'm not exactly sure which one makes sense but uh hopefully i didn't pick the the wrong directions um so now i know the directions i can i can tell uh what this position means right well it's it's not that easy unfortunately i just lost my control all right it's not it's not it's not that easy i also need to know the this origin over here so it's not just the directions but i need to know the origin now okay you may think that oh this is so trivial stuff why are you wasting time here this is important this is very important and oftentimes missed a vector on its own is entirely meaningless it does not mean anything unless you provide a context only within this context a vector has a meaning right in this context if i say that this is my origin position and these are my x y and z directions that's when a vector has a meaning now when i give you this vector that says 5 7 3 i can say all right i'm going to walk 5 units along x and then 7 units along y and then three units along z and that's going to be the position right so now it has a meaning and this is very very important because when we're doing some subgraphic stuff we're going to be using different coordinate frames for different things and if i give you a vector in one coordinate frame and i give you another vector in a different coordinate frame you cannot do anything with these two vectors because they are living in different spaces if you want to do anything with these two vectors you need to first move them into the same space and then you can do something with them so it's very important to understand that a vector is meaningless without this context okay so now going back to this question of position or direction a vector would mean let's say a position if if it means a position it also means that the direction from the origin to that position right so that direction is also uh is also the meaning of this this vector so that's why even though there are these two different meanings of a vector in terms of computer graphics um we typically use a single type to represent a vector because there are sort of in some ways interchangeable when you think about a vector in the context of a coordinate frame you can think about a position as a direction from the origin of the coordinate frame right and this is how these two meanings come together all right simple stuff but i just wanted to emphasize and make sure that we all um uh i can't we all can think about vectors in this one now um in mathematics often times i just want to i don't want to write a vector like this because it's too long i'm just going to represent it as a single value let's call it a and this is a very typical notation for a vector you you put an arrow on top for whatever reason we don't like it in geographics we typically use a slightly different notation uh not always but the typical notation in computer graphics would use a bold lowercase letter that would mean that this is probably a vector right i mean this varies when you're reading books and papers about computer graphics and people may use different notations but this is the most common notation that's used in computer graphics so bold letter you realize that oh this is probably a vector and if i have x y and z components of a vector i can write them as like a is my vector so i can say ax a y and a z as my components again but as you can see these scalars are not bold and they're also italicized so that's that's the typical notation that we use and this is written in column vector format all good so one of the first things i'm going to say about vectors is the the length of a vector that's going to be this is the notation for the length of a vector and it's going to be x squared and y squared ac squared sub right and you know where this is coming from right so it's just that the length of the vector as the pythagorean theorem will tell you how to compute it and this is what it is and i'm telling you this because a very very very important concept in terms of vectors is the concept of the unit vector now we're going to be using unit vectors quite a bit and it's going to be very important for a lot of our computation a unit vector is a vector that has a length one unit whatever your unit is and that's going to make um that that's going to be very very important uh that we're going to a lot of times we're going to get a vector and we're going to take that vector and we're going to shrink it down or adjust this length such that it becomes a unit vector because we will need a unit vector to define that particular direction we won't care about its length we'll just care about its direction in which case uh we're gonna convert it to unit vector because that will allow you to do some some mathematical operations uh all right so a vector can also be represented as a you know a line with an arrow so that's my vector let's say this is vector a uh the negative of vector a would be the vector going in the opposite direction right that's negative vector a actually maybe i shouldn't put it this way because i told you a vector on its own does not make much sense we need to provide the context probably in probably this point over here was our origin right so negative a should be this so so if this is this is a negative a should be should be this guy over here um because you know origin is important all right what else can i do well i can add two vectors in this case um a plus b is a plus b right and you know i can write it in this form i can just the way you add it is just you add the x y and z components and you're done can i do subtraction fairly easily i can do subtraction yes in this case we're doing b minus a so i'm going in the opposite direction so b minus a now you can think that this is very trivial and probably it is if you're familiar with vectors it is trivial stuff but it's stuff that you kind of need to be you need to be used to thinking about you need to get used to thinking about in these visual terms and you know this is done the equation for it very very simple now when it comes to um multiplication there are actually multiple ways of doing multiplication with vectors um probably the most common one is the dot product that product will take two vectors and it will form a scalar out of those two vectors so this is the the formula for dot product you just multiply x y and z components and add them together right that's our dot product that's the result is going to be a scalar um now that product is used quite extensively in computer graphics for all sorts of things so let's talk about it just just a little bit um but before i go in go go into it i would like you to to recognize something so the dot product of a vector to itself so a dot a would be that would be a squared that would be the squared length of the vector itself right and that's that's also used a lot um uh for all sorts of notation we sometimes do just double product of a vector by itself that means that the square squared of its length all right but that product means also other things that are very very important for us for example imagine this case imagine that i would like to know the the projection of this this vector a along this direction b and i would like to know this length this length d is what i would like to know i can use dot product to compute that now if my vector b here is a unit vector if this is a unit vector that means its length is one then the dot product is going to give me the length the the this length over here the length of this projection and that's a very very important property and we're going to be using this property quite a lot so but what happens if b is not a unit vector well then in general case okay i'm just going to divide it by the length of b all right so d is going to be um a dot product b divided by the length of b right so notice that here it's not symmetrical right so i'm not dividing by the length of a or anything so this b is here so that b divided by the length of b will give me a unit vector right so i'm basically taking a dot product with a unit vector effectively that's why it's there if i want to know the projection of b on the direction of a over here then i'm gonna divide it by the length of a right then a has to be a vector because then then i'll be interested in the direction of a but not necessarily magnitude another thing is the the angle between two vectors um this is a very very important equation and we'll we will be using that uh quite a lot uh so down for that can also be written as the length of a times the length of b times the cosine of the angle between the two of them uh sometimes we will need the cosine of the angle between two directions you will see that this is a very very useful concept later on uh i'm not getting into the details of why it's useful at the moment but believe me when i download it it's very very useful and oftentimes we will be dealing with unit vectors right i'm going to have unit vector a i'm going to have a unit vector b in which case the length of a length of b are going to be just one so they will cancel out so the dot product will give me the cosine of the angle between the two of them where the two of them are unit vectors right and we're going to be using this this property quite a lot as well all right so another property that we're going to be using is that if these two vectors are perpendicular to each other then the cosine of the angle between the two of them will be zero right and if the cosine is zero then the whole right-hand side of that equation uh will become zero so dot product of two perpendicular vectors will give me zero and this is great because if i want to check whether or not two vectors are perpendicular to each other i can easily use this right and this gives me a scalar and it tells me if they are perpendicular but be warned here this is not the only condition when i'm going to have the doctor like zero i can have one of my vectors a zero vector well in which case maybe it's okay to assume that a zero vector is perpendicular to every other vector i don't know i i don't know if it actually makes sense but maybe that's one way to think about it all right uh so here are some dot product identities uh simple stuff you can swap the order of a and b that's perfectly fine you can compute them in whatever order you want and if you you know multiply one of them with some scalar you can just move that scale to the other one or just move it out and just take that product and then scale it and you know it all comes from the data product formulation so all of this is coming from that product foundation so this is the number like this is the the the form the this is the uh vector operation that we're going to be using quite extensively uh probably the most extensively uh so i wanted to spend quite a bit of time here just get you guys familiar with it although the math behind it is relatively simple it's not anything complicated right here's our other product cross product so cross product would take two vectors um a and b and it would form a third vector in this case it's shown as a cross b and this third vector is going to be perpendicular to both of these vectors so a and b they don't have to be perpendicular to each other they're just some arbitrary vectors but the vector i'm getting out of them is perpendicular to both of them that's that's very very important um and oftentimes we're going to use cross products for that very property oftentimes we're going to use cross products so that we can get a vector that is perpendicular to both of these vectors another related thing here is that so in 2d how am i going to define a cross product in 2d because how can i get two vectors a and b in 2d on a plane and the third vector a cross b has to be sort of sticking out of the plane right so if you look at this a and b it's sort of defining a plane here and my third vector is going to be perpendicular to that plane so it's not it it is possible to define cross in 2d but it doesn't become a vector in 2d then cross cross product in 2d actually becomes a scalar all i get is going to be the the length of this vector not the not the direction because this direction is sort of outside of this 2d domain does that make sense so in 2d you can think about cross product as something that produces a scalar and what's that going to give that skill is going to be the area of this slowly parallelogram here it's going to give me the area of this parallelogram in 3d i'm going to get a vector that is perpendicular to these two vectors and it's going to be outside of this this plane that these two vectors live in and its length is going to be the area of this parallelogram over here now as you can see this is quite useful i mean i can i can i i we're going to use it oftentimes for just for the purpose of getting a perpendicular uh vector uh but sometimes we can use it for measuring the area between these two angles between these two vectors and one thing to note here is that so if these two vectors a and b if they are in the same direction if they are i have one vector and another vector on top of that if they are in the same direction then this area is going to be zero right and they don't have to have the same same length as long as they're in the same direction this area is going to be zero and if this area is zero then my cross product is going to be a vector with zero length so that's going to be the zero vector right uh yeah i'm gonna get a zero vector with no discernible direction because it's gonna be zero zero zero all right um so close for that is not as nice as does product in the way that it behaves in equations it's a bit more complicated i'm not giving you the formulation for crossbar but it's fairly easy to find um if you don't remember um but what's important to to remember is that the cross product of um of a cross b and this is the negative um negative a cross b so if i just take a and flip it around and now it goes in that direction so that's negative a so a cross b is going to give me this direction negative a cross b is going to give me the opposite direction all right and we can handle this using right-handed coordinate frame uh if you're not sure which which direction to use so x y z um all right so as i said it doesn't behave as as nicely so if you change the order of turns you're going to get the the the opposite direction uh a scalar times that the scalar will will come out that's going to be fine and it says this distributive property uh and that's going to be um yeah a cross uh b plus c is going to be a cross b plus a cross c and we are we're using stuff like this just to uh drive stuff but you know just just to just just just wanted to provide this three basic information you can find more uh information about crossfire uh when we need you there's a question here can you use the the thumb curls to determine the direction yes that's right what i like to use is i like to put my hand like this what i prefer is i picked the first vector a and then b so this is going to give me the the result that's what i like to use but you know there are different ways of doing this as well uh right hand i'm not sure if this appears for you as my right hand or my left hand i i i think it uses my right hand so it should be okay all right so there are there is one more product definition for vectors but the output of that product definition is going to be a matrix and we're not going to be using it that often uh we will be using it sometimes um you know this this linear algebra is used a lot in computer graphics for all sorts of things but for general stuff that product and cross product is basically all we need so do we we're done i just wanted to very briefly mention matrices uh so we're going to be using matrices quite a bit i'm not getting into details of matrices today too much because uh you know we're going to be using we're going to be talking about transformations very soon and transformations are all about matrix operations so we're going to talk about matrices quite a bit then um so i'll leave it to to that time but just uh you know just to touch on matrices a little bit uh so a three by three matrix will have nine components like this and when for matrix notation you know these are the nine scalars uh we typically use um uppercase uh uppercase bold letters typically not always but that's that that's the the most common notation for for representing matrices that's used in computer graphics literature um matrices can be you know very can have various dimensions in x and y but typically what we're interested in will be matrices in 2d3 3d and 4d and those are going to be two by two matrices three by three matrices and four by four matrices so these are the most common matrices that we will be using in computer graphics you will also see three by four major scenes but they're typically a substitute for a four by four matrix i'll we'll we'll talk about that uh so if you see uh three by four matrices just think that it's actually supposed to be a four by four matrix they're just um ignoring the the last column because for whatever operations they're using it's not needed and we'll talk about that so don't worry about it uh but basically these are the matrices that we'll be interested in now again for certain operations in computer graphics that that commonly used in for example uh for solving optimization problems um but you may use much much larger matrices that million by a million is definitely a reasonable matrix that actually people use uh but those are those are very specific to certain tasks uh for most operations in computer graphics will typically be dealing with two by two if you're dealing with 2d 2d graphics if we're dealing with 3d graphics it's going to be three by three and four by four matrices is what we're going to what we're going to be dealing with right um and the most common operation that we will be using uh with matrices though you're going to take a matrix and we're just going to multiply a vector by a matrix and this operation is going to be the basic operation that we're going to be using for transforming vectors from one coordinate frame to another coordinate frame so that's going to be the important part now i'm seeing some question the fourth dimension this time though the fourth dimension is not quite time it's a little bit of a hack that we like using it's called homogeneous coordinates um and i'm gonna explain what it means um in the context of transformation so don't don't worry about it for the time being uh so we're not thinking about the time dimension uh and you know matrices are not um are not very often used for handling time related stuff um all right matrices are used a lot in animation but we're not gonna have like five by five matrices because we have the time to mention or anything but we're not doing that um i'm not saying that it doesn't happen at all i'm just saying it's it's not a general practice so we we're not gonna worry about that so why we need four by four matrices will make a lot more sense when we're talking about transformations just for the time being just know that they exist and the reason why i'm talking about that is just to tell you that you know it's a big topic right there are lots of things about matrices uh but the things that we're mostly going to be dealing with is just going to be this right nothing scary just multiply a vector by a matrix that that's what it is and this matrix is oftentimes going to be a square matrix it's going to be two by two three by three or five by five four by four matrix that's it right okay we're also going to multiply matrices by other matrices we're gonna multiply two images together that's another thing we're going to do so um let's see that the important thing to understand here is that a times b and b being two matrices it's not equal to b times a that that's the point that i wanted to make here ah okay so uh you know this is the very very very basic math stuff that we're going to be relying upon uh you know not nothing complicated i'm pretty sure you guys are all familiar with it so maybe you think that this this lecture was a waste of time for some of you hopefully it wasn't a waste of time for everybody um and uh you know what i would like you to get out of this is to uh think about vectors as uh directions and positions in in in space uh in in and and think about them in visual terms uh because that's how we're going to handle these uh vectors that's how we're going to use these vectors
Info
Channel: Cem Yuksel
Views: 5,130
Rating: undefined out of 5
Keywords:
Id: DnkU4_DttGE
Channel Id: undefined
Length: 33min 39sec (2019 seconds)
Published: Sat Jan 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.