WEBVTT 1 00:00:05.619 --> 00:00:09.900 Game Basics Mathematical Fundamentals 6 (Dot Product) 2 00:00:09.900 --> 00:00:12.141 GCC Academy 3 00:00:27.639 --> 00:00:29.200 Hello everyone 4 00:00:29.201 --> 00:00:31.101 I am Lee Deuk-woo for gaming maths 5 00:00:31.101 --> 00:00:34.360 This session focuses on the concept of the dot product 6 00:00:34.680 --> 00:00:36.441 We’ll discuss 7 00:00:36.442 --> 00:00:41.171 what a dot product is and how it can be applied 8 00:00:41.172 --> 00:00:45.067 Dot Product 9 00:00:45.599 --> 00:00:48.401 The dot product 10 00:00:48.401 --> 00:00:54.769 is a specialized operation performed on vectors 11 00:00:55.153 --> 00:01:00.320 Previously, we reviewed basic vector operations 12 00:01:00.560 --> 00:01:04.170 such as vector addition and scalar multiplication 13 00:01:04.170 --> 00:01:08.806 These two were the basic operations 14 00:01:08.806 --> 00:01:14.360 that allow us to create new vectors 15 00:01:14.360 --> 00:01:18.220 in a vector space through linear combinations 16 00:01:18.879 --> 00:01:22.721 However, these fundamental operations alone 17 00:01:22.721 --> 00:01:24.664 may not be sufficient in using vectors 18 00:01:25.080 --> 00:01:31.143 To address this, mathematicians developed special operations 19 00:01:31.144 --> 00:01:35.092 that are particularly useful and widely applied 20 00:01:35.440 --> 00:01:38.400 They are dot and cross products 21 00:01:38.687 --> 00:01:42.927 Today, we’ll delve into the dot product 22 00:01:44.740 --> 00:01:49.341 Here are some useful operations for you 23 00:01:49.342 --> 00:01:50.843 The multiplication of vectors 24 00:01:50.844 --> 00:01:55.143 The corresponding components are multiplied in the operation 25 00:01:55.423 --> 00:02:01.123 However, this method is mainly used in contexts like mixing colors 26 00:02:02.144 --> 00:02:05.749 and is rarely applied to other practical uses of vectors 27 00:02:06.203 --> 00:02:09.381 On the other hand, the dot product, which we’ll discuss now 28 00:02:09.382 --> 00:02:14.741 is utilized in almost all applications involving vectors 29 00:02:14.980 --> 00:02:20.857 Approximately 70–80% of vector-related operations 30 00:02:20.858 --> 00:02:25.803 begin with the dot product, so it is a very important operation 31 00:02:26.219 --> 00:02:28.641 Another related operation is the cross product 32 00:02:28.641 --> 00:02:32.311 This applies exclusively to three-dimensional vectors 33 00:02:32.600 --> 00:02:35.221 We will discuss the cross product in more detail later 34 00:02:35.221 --> 00:02:38.051 when we delve into three-dimensional vector operations 35 00:02:39.300 --> 00:02:42.780 Let’s focus on the dot product 36 00:02:43.099 --> 00:02:46.419 The dot product, as you can see 37 00:02:46.420 --> 00:02:49.103 involves two two-dimensional vectors 38 00:02:49.319 --> 00:02:50.401 multiplying 39 00:02:50.742 --> 00:02:54.234 the x-components together and the y-components together 40 00:02:54.234 --> 00:02:57.909 then summing these products 41 00:02:58.240 --> 00:03:03.001 This process is not limited to two dimensions 42 00:03:03.002 --> 00:03:05.212 It can extend to three, four 43 00:03:05.212 --> 00:03:08.123 or even n-dimensional vectors 44 00:03:08.123 --> 00:03:11.278 Multiply the corresponding components and sum the result 45 00:03:11.279 --> 00:03:15.092 Regardless of the number of dimensions 46 00:03:15.093 --> 00:03:16.893 the operation remains consistent 47 00:03:17.340 --> 00:03:18.642 The dot product involves 48 00:03:18.642 --> 00:03:23.153 multiplying corresponding components of the vectors and summing them 49 00:03:23.162 --> 00:03:27.776 which always results in a scalar value 50 00:03:29.479 --> 00:03:33.821 The properties of the dot product can 51 00:03:33.821 --> 00:03:35.240 be summarized as follows 52 00:03:35.544 --> 00:03:37.924 First, the dot product satisfies the commutative property 53 00:03:38.184 --> 00:03:43.141 Since the operation involves scalar multiplication and addition 54 00:03:43.381 --> 00:03:47.720 where both multiplication and addition 55 00:03:47.721 --> 00:03:52.141 are commutative 56 00:03:52.141 --> 00:03:57.260 the dot product naturally adheres to this property 57 00:03:57.780 --> 00:04:00.041 Next is the associative property 58 00:04:00.352 --> 00:04:03.011 The associative property is difficult to apply 59 00:04:03.012 --> 00:04:08.151 because he operation transitions into scalar-vector multiplication 60 00:04:08.640 --> 00:04:11.500 It's not an equivalent operation to the original dot product 61 00:04:11.501 --> 00:04:14.221 The result involves scalar-vector multiplication 62 00:04:14.222 --> 00:04:16.538 so that is the operation here 63 00:04:16.839 --> 00:04:20.776 Same thing here, it's scalar-vector multiplication 64 00:04:21.157 --> 00:04:25.936 So it is not an operation where identical components 65 00:04:26.177 --> 00:04:30.657 are processed in a sequential manner twice 66 00:04:31.240 --> 00:04:33.758 For the associative property 67 00:04:34.579 --> 00:04:38.244 the operation’s nature itself is incompatible, and the resulting value is fundamentally different 68 00:04:38.604 --> 00:04:40.884 So, the associative property 69 00:04:40.885 --> 00:04:42.626 is not applicable to the dot product 70 00:04:43.446 --> 00:04:45.721 Now, let’s consider the distributive property 71 00:04:46.062 --> 00:04:47.722 In the case of the distributive property 72 00:04:47.723 --> 00:04:52.500 if we first calculate the vector addition and then perform the dot product 73 00:04:52.500 --> 00:04:55.228 the result will be a scalar 74 00:04:55.640 --> 00:04:58.689 Similarly, if we perform the dot product on each term individually 75 00:04:58.689 --> 00:05:00.894 and then sum the scalar results 76 00:05:01.055 --> 00:05:04.915 the outcome will be the same 77 00:05:04.915 --> 00:05:07.640 This demonstrates that the dot product 78 00:05:07.640 --> 00:05:09.192 satisfies the distributive property 79 00:05:09.559 --> 00:05:11.220 To summarize 80 00:05:11.221 --> 00:05:16.116 the dot product satisfies the commutative property but does not satisfy the associative property 81 00:05:16.302 --> 00:05:19.702 However, it does satisfy the distributive property 82 00:05:21.920 --> 00:05:28.326 Now, if we examine the characteristics of the dot product 83 00:05:28.327 --> 00:05:31.233 through the lens of the distributive property 84 00:05:31.497 --> 00:05:35.536 The dot product applied to the addition of the same vectors 85 00:05:36.000 --> 00:05:40.302 We get terms like u.u, and u.v 86 00:05:40.502 --> 00:05:42.980 v.u and v.v 87 00:05:42.981 --> 00:05:47.255 Due to the commutative property, u.v and v.u are equal 88 00:05:47.444 --> 00:05:53.303 which simplifies the expression to u.u, v.v, e.u.v 89 00:05:53.920 --> 00:05:57.981 When we calculate the dot product 90 00:05:57.981 --> 00:05:59.501 of the same vector with itself 91 00:05:59.920 --> 00:06:03.520 as seen here, it results to where 92 00:06:03.890 --> 00:06:07.390 each component is squared 93 00:06:07.390 --> 00:06:10.781 For example, the first component is squared 94 00:06:11.002 --> 00:06:14.681 the second component is squared, and so on 95 00:06:14.682 --> 00:06:16.270 That's what we get 96 00:06:16.600 --> 00:06:18.669 This operation ultimately corresponds 97 00:06:18.669 --> 00:06:24.063 to the square of the norm of the vector 98 00:06:24.359 --> 00:06:29.321 Therefore, taking the dot product of a vector with itself 99 00:06:29.322 --> 00:06:31.756 always results in the square of its norm 100 00:06:31.756 --> 00:06:35.288 or the square of its length 101 00:06:35.674 --> 00:06:39.480 Thus, the equation above can be rewritten 102 00:06:39.800 --> 00:06:41.901 in terms of squared magnitudes 103 00:06:42.137 --> 00:06:44.737 the square of the norm of vector u 104 00:06:44.917 --> 00:06:47.237 the square of the norm of vector v 105 00:06:47.237 --> 00:06:53.166 and the interaction term e.u.v 106 00:06:53.166 --> 00:06:55.660 This equation is formed in this way 107 00:06:55.901 --> 00:06:59.301 and since it will prove useful later 108 00:06:59.301 --> 00:07:01.696 I wanted to mention it here 109 00:07:03.160 --> 00:07:05.557 To summarize 110 00:07:06.309 --> 00:07:09.709 the norm of vector v is calculated 111 00:07:09.709 --> 00:07:13.229 as the square root of the sum of the squares of its components 112 00:07:14.313 --> 00:07:18.152 When the same vector is involved in the dot product with itself, the result is always the square of this norm 113 00:07:19.188 --> 00:07:20.429 For any n -dimensional vector 114 00:07:20.549 --> 00:07:26.457 the dot product of the vector with itself yields the square of its norm 115 00:07:26.457 --> 00:07:29.020 That's the conclusion we get 116 00:07:29.880 --> 00:07:32.220 Using these properties 117 00:07:32.476 --> 00:07:34.895 the dot product can be applied in various ways 118 00:07:35.320 --> 00:07:38.381 First, it’s important to understand the properties of the dot product 119 00:07:38.381 --> 00:07:41.396 which are closely related to trigonometric functions 120 00:07:41.640 --> 00:07:45.559 particularly the cosine function 121 00:07:46.119 --> 00:07:49.621 In fact, the reason the dot product 122 00:07:50.762 --> 00:07:53.953 is so widely used in game production 123 00:07:53.954 --> 00:07:56.536 in its application, in particular 124 00:07:56.920 --> 00:08:00.041 because it relates to the cosine function 125 00:08:00.310 --> 00:08:03.709 By leveraging the properties of the cosine function 126 00:08:03.710 --> 00:08:07.630 the dot product can be utilized in a variety of situations 127 00:08:08.480 --> 00:08:10.719 So, the formula for that is as follows 128 00:08:10.859 --> 00:08:14.215 The dot product of a and b 129 00:08:14.614 --> 00:08:17.913 is equal to the product of the magnitude of vector a and that of b 130 00:08:17.913 --> 00:08:23.147 and the cosine of the angle theta between them 131 00:08:23.147 --> 00:08:26.547 This formula is what enables this 132 00:08:26.719 --> 00:08:30.799 To understand how this formula is derived, let’s briefly examine it 133 00:08:31.539 --> 00:08:35.419 First, imagine an arbitrary triangle with points 134 00:08:35.419 --> 00:08:38.259 point A, B, and C 135 00:08:38.260 --> 00:08:41.400 Place point B at the origin 136 00:08:41.699 --> 00:08:45.980 Define the vector pointing from B to A as vector C 137 00:08:46.241 --> 00:08:49.214 and the vector pointing from B to C as vector a 138 00:08:49.214 --> 00:08:58.320 so the side opposite point A is referred to as vector a 139 00:08:58.320 --> 00:09:01.379 So the side opposite to that is vector b 140 00:09:02.039 --> 00:09:04.621 When arranging the triangle in this way 141 00:09:05.591 --> 00:09:10.351 we can use this triangle 142 00:09:10.352 --> 00:09:13.584 to derive the cosine formula over here 143 00:09:14.000 --> 00:09:19.040 Point B is set at the origin, two sides as vectors 144 00:09:19.040 --> 00:09:22.773 so b defined as (0, 0) 145 00:09:23.119 --> 00:09:30.530 Point C is positioned to align with the x-axis 146 00:09:31.383 --> 00:09:38.574 The side opposite point A is defined as vector a 147 00:09:38.574 --> 00:09:41.901 If we set vector a in the positive direction 148 00:09:41.902 --> 00:09:43.948 its magnitude 149 00:09:43.949 --> 00:09:45.627 corresponds to the norm of vector a 150 00:09:45.627 --> 00:09:46.547 So it's the length 151 00:09:46.840 --> 00:09:50.460 So it's vector a norm, 0 152 00:09:50.880 --> 00:09:53.860 Now, for point A 153 00:09:54.150 --> 00:09:56.670 assume the angle 154 00:09:57.242 --> 00:10:04.801 between vectors c and a is beta 155 00:10:04.801 --> 00:10:09.284 To determine the height 156 00:10:09.285 --> 00:10:16.129 we refer to unit circle properties 157 00:10:16.129 --> 00:10:22.341 For a vector with a magnitude of 1 158 00:10:22.341 --> 00:10:25.460 the x-component is cosine theta 159 00:10:25.460 --> 00:10:27.739 and the y-component is sine theta 160 00:10:27.739 --> 00:10:33.580 If the radius is r, the components become r cosine theta and r sine theta 161 00:10:34.042 --> 00:10:41.680 With vector c, whose magnitude is known 162 00:10:42.500 --> 00:10:44.620 and the angle beta 163 00:10:44.882 --> 00:10:49.302 it's the norm of c times cosine beta for the x-coordinate 164 00:10:49.562 --> 00:10:51.617 and the norm of c times sine beta for the y-coordinate 165 00:10:52.959 --> 00:10:56.359 If the positions of the points are defined as stated 166 00:10:56.360 --> 00:10:59.344 we can calculate vector b 167 00:10:59.679 --> 00:11:02.181 Vector b is pointing from point C to point A 168 00:11:03.125 --> 00:11:06.384 or equivalently, from point A to point C 169 00:11:06.760 --> 00:11:12.179 The coordinates of vector b can be determined based on earlier definitions 170 00:11:13.019 --> 00:11:15.500 Next, we calculate the magnitude of vector b 171 00:11:16.230 --> 00:11:21.229 and then examine the result of squaring this magnitude 172 00:11:21.599 --> 00:11:25.440 Squaring each component of vector b results in an expanded form 173 00:11:25.640 --> 00:11:31.090 The sum of the square of the norm of vector a, that of vector c 174 00:11:31.091 --> 00:11:35.681 and twice the product of the norms of vectors a and c 175 00:11:35.682 --> 00:11:39.276 multiplied by the cosine of the angle beta between them 176 00:11:39.880 --> 00:11:44.632 When the magnitude of vector b is squared 177 00:11:44.633 --> 00:11:50.269 it is equivalent to taking the dot product of vector b with itself 178 00:11:50.394 --> 00:11:55.180 Thus, this result represents b.b 179 00:11:55.440 --> 00:11:59.680 which can also be expressed in terms of vectors a and c 180 00:11:59.980 --> 00:12:02.020 by rewriting the relationship 181 00:12:02.021 --> 00:12:04.048 So that's the dot product 182 00:12:04.048 --> 00:12:05.581 Specifically, the result becomes 183 00:12:06.755 --> 00:12:12.015 the sum of the square of the norm of vector a, that of vector c 184 00:12:12.620 --> 00:12:23.060 and -2a.c, where a.c is the dot product of vectors a and c 185 00:12:23.060 --> 00:12:26.639 So this value is same as the one over here 186 00:12:26.919 --> 00:12:28.601 From here, by canceling out 187 00:12:28.862 --> 00:12:32.423 the square of the norm of a and the square 188 00:12:32.423 --> 00:12:33.400 of the norm of c 189 00:12:33.640 --> 00:12:35.834 we find that the dot product a.c 190 00:12:35.834 --> 00:12:43.791 equals the product of the magnitudes of vectors a and c 191 00:12:45.730 --> 00:12:49.520 multiplied by the cosine of the angle beta between them 192 00:12:49.521 --> 00:12:51.681 So this is the conclusion we get 193 00:12:52.760 --> 00:12:58.380 Using the dot product 194 00:12:59.006 --> 00:13:03.745 we derived the cosine formula from trigonometric principles 195 00:13:04.119 --> 00:13:06.924 If the magnitudes of the two vectors 196 00:13:06.924 --> 00:13:08.396 are both 1, the formula simplifies further 197 00:13:08.396 --> 00:13:11.398 reducing to the cosine of the angle 198 00:13:11.399 --> 00:13:14.715 between the two vectors, the cosine of theta 199 00:13:14.968 --> 00:13:17.520 This property is highly useful in various applications 200 00:13:17.521 --> 00:13:22.679 We can effectively utilize proportional relationship 201 00:13:22.679 --> 00:13:24.640 between the dot product and the cosine function 202 00:13:26.120 --> 00:13:31.661 The cosine function’s properties can be applied in various ways 203 00:13:31.661 --> 00:13:33.936 with one of the most notable applications 204 00:13:33.937 --> 00:13:35.337 being orthogonality testing 205 00:13:35.337 --> 00:13:40.099 This determines whether two vectors are perpendicular to each other 206 00:13:40.659 --> 00:13:44.102 If the dot product of two vectors equals 0 207 00:13:44.102 --> 00:13:49.101 it implies that the cosine of the angle theta between them must also be 0 208 00:13:49.101 --> 00:13:52.524 For this to happen 209 00:13:52.525 --> 00:13:53.779 if not 0 210 00:13:53.779 --> 00:13:56.468 the cosine of theta can only be 0 211 00:13:56.468 --> 00:13:58.308 for this value to be 0 212 00:13:58.760 --> 00:14:01.521 So when does the cosine of theta become 0? 213 00:14:01.521 --> 00:14:03.281 90 and 270 degrees 214 00:14:03.281 --> 00:14:07.621 It's when the angle is 90 and -90 degrees 215 00:14:07.621 --> 00:14:12.760 The condition for the dot product to be 0 directly 216 00:14:12.761 --> 00:14:15.121 translates into the vectors being orthogonal 217 00:14:16.320 --> 00:14:22.330 By leveraging this property of the dot product 218 00:14:22.799 --> 00:14:24.740 we can tell 219 00:14:24.740 --> 00:14:30.264 that the dot product of two vectors is 0 220 00:14:30.919 --> 00:14:32.341 and it happens when 221 00:14:32.341 --> 00:14:36.073 the two vectors are perpendicular 222 00:14:36.440 --> 00:14:41.079 If we calculate the dot product of the standard basis vectors 1, 0 and 0, 1 223 00:14:41.080 --> 00:14:44.292 1 by 0 by 0 by 1 224 00:14:44.599 --> 00:14:46.281 it's a 0 225 00:14:46.281 --> 00:14:49.856 This result indicates that the vectors are orthogonal 226 00:14:50.320 --> 00:14:53.701 If we then rotate these vectors by an angle theta 227 00:14:53.702 --> 00:14:56.851 so the perpendicular vector is rotated by theta 228 00:14:56.851 --> 00:14:59.757 so the rotated vectors remain orthogonal 229 00:15:00.000 --> 00:15:05.900 However, instead of relying on visual intuition 230 00:15:06.180 --> 00:15:08.925 we can simply calculate the dot product of the rotated vectors 231 00:15:09.679 --> 00:15:11.800 If the rotated vectors are represented as (cosine theta, sine theta) 232 00:15:11.800 --> 00:15:13.988 and (negative sine theta, cosine theta) 233 00:15:13.988 --> 00:15:15.777 their dot product becomes 234 00:15:16.119 --> 00:15:18.820 cosine theta times negative sine theta 235 00:15:19.007 --> 00:15:22.487 plus sine theta times cosine theta, which is 0 236 00:15:22.487 --> 00:15:25.787 This confirms that 237 00:15:26.027 --> 00:15:30.260 the two rotated vectors are also orthogonal 238 00:15:31.100 --> 00:15:33.600 Building on this concept 239 00:15:36.127 --> 00:15:38.067 we can introduce the idea of a rigid transformation 240 00:15:38.068 --> 00:15:38.988 So 241 00:15:38.989 --> 00:15:42.589 rigid means firm or solid 242 00:15:42.589 --> 00:15:46.721 and in physics, it refers to a rigid body 243 00:15:46.721 --> 00:15:50.673 which is a solid object whose shape does not deform 244 00:15:51.320 --> 00:15:54.261 A rigid body 245 00:15:54.261 --> 00:15:56.881 It's rigid body in physics 246 00:15:56.882 --> 00:15:59.439 It can be thought of in a similar way 247 00:15:59.439 --> 00:16:02.761 as in game development 248 00:16:03.326 --> 00:16:06.265 Rigid transformation refers to 249 00:16:06.880 --> 00:16:10.400 a type of transformation where the object’s shape 250 00:16:11.141 --> 00:16:14.701 remains unchanged during the transformation 251 00:16:14.701 --> 00:16:16.120 Rigid transformation 252 00:16:16.121 --> 00:16:21.340 For a transformation to qualify as a rigid transformation, the following must be satisfied 253 00:16:22.679 --> 00:16:28.420 After the transformation, the magnitude of all basis vectors must remain 1 254 00:16:28.420 --> 00:16:32.472 All basis vectors must remain orthogonal to each other 255 00:16:32.512 --> 00:16:36.880 because the original vectors in the space are orthogonal 256 00:16:37.015 --> 00:16:40.714 and this property must be preserved after the transformation 257 00:16:41.239 --> 00:16:44.660 The determinant of the transformation matrix must be 1 258 00:16:44.841 --> 00:16:47.739 to ensure that the object does not flip 259 00:16:48.120 --> 00:16:54.695 To confirm that a transformation is rigid 260 00:16:54.695 --> 00:16:57.471 we can verify that the determinant of the transformation matrix is 1 261 00:16:57.739 --> 00:16:58.959 Rigid transformation 262 00:16:58.960 --> 00:17:01.880 It ensures that the shape of the object 263 00:17:01.880 --> 00:17:03.244 remains completely unchanged 264 00:17:03.460 --> 00:17:06.889 A prime example of a rigid transformation is rotation 265 00:17:07.318 --> 00:17:09.258 When examining rotational transformations 266 00:17:09.579 --> 00:17:13.152 we see that the magnitude of each basis vector 267 00:17:13.658 --> 00:17:18.182 in the transformed space remains 1 268 00:17:18.182 --> 00:17:22.002 Let's consider the basis vector represented by cosine theta and sine theta 269 00:17:22.382 --> 00:17:26.082 Its norm is given by the square root of cosine squared theta plus sine squared theta 270 00:17:26.082 --> 00:17:29.562 According to the Pythagorean theorem 271 00:17:29.562 --> 00:17:31.166 we know this equals 1 272 00:17:31.560 --> 00:17:36.521 When squared, the negative sign in the second basis vector disappears 273 00:17:36.522 --> 00:17:38.798 resulting in cosine squared theta plus sine squared theta 274 00:17:39.087 --> 00:17:42.467 The second basis vector also has a magnitude of 1 275 00:17:42.680 --> 00:17:45.880 It hold true regardless of whether we examine the vectors horizontally or vertically 276 00:17:46.654 --> 00:17:48.854 We also previously verified that the basis vectors 277 00:17:48.855 --> 00:17:51.255 remain orthogonal to each other 278 00:17:51.719 --> 00:17:54.040 Next, let’s examine the determinant of the transformation matrix 279 00:17:54.041 --> 00:17:55.693 ad-bc 280 00:17:55.693 --> 00:18:00.387 In this case, cosine squared theta plus sine squared theta 281 00:18:00.388 --> 00:18:02.204 is equal to the determinant value ad - bc 282 00:18:02.205 --> 00:18:04.641 This confirms that the determinant of the matrix is 1 283 00:18:05.119 --> 00:18:07.220 Such a rotational transformation 284 00:18:07.221 --> 00:18:14.600 ensures that the shape and structure of an object remain 285 00:18:14.600 --> 00:18:16.764 unchanged after the transformation 286 00:18:16.959 --> 00:18:20.000 This is the rigid transformation 287 00:18:20.502 --> 00:18:24.642 Application of the Dot Product 288 00:18:25.040 --> 00:18:29.859 Let’s examine how the dot product is practically applied 289 00:18:30.199 --> 00:18:33.072 One prominent application is determining the front or the back 290 00:18:33.480 --> 00:18:36.919 By using the cosine formula embedded in the dot product 291 00:18:36.920 --> 00:18:41.266 we can evaluate the relative position of a target 292 00:18:42.165 --> 00:18:45.760 For example, imagine a person facing 293 00:18:45.761 --> 00:18:49.277 forward with a view vector 294 00:18:49.277 --> 00:18:51.372 If there is an object in space 295 00:18:51.372 --> 00:18:53.260 we can define a vector 296 00:18:54.020 --> 00:18:56.980 pointing from the person to the object 297 00:18:57.479 --> 00:19:00.520 When the angle between 298 00:19:00.736 --> 00:19:02.396 these two vectors is theta 299 00:19:02.982 --> 00:19:07.201 taking their dot product produces a value proportional to cosine theta 300 00:19:07.479 --> 00:19:09.120 The graph of cosine 301 00:19:09.121 --> 00:19:11.943 starts at 1 when x equals 0 302 00:19:11.944 --> 00:19:16.521 and decreases as the angle moves 303 00:19:16.521 --> 00:19:18.278 How does it work? 304 00:19:18.279 --> 00:19:22.532 Toward 90 degrees or negative 90 degrees 305 00:19:22.532 --> 00:19:23.839 reaching 0 at these limits 306 00:19:23.840 --> 00:19:26.480 beyond this, the cosine value turns negative 307 00:19:26.834 --> 00:19:32.761 This means that the values are positive from -90 degrees to 90 degrees 308 00:19:32.762 --> 00:19:35.984 As long as the angle between the two vectors 309 00:19:35.984 --> 00:19:41.259 the values remain positive until they reach plus and minus 90 degrees 310 00:19:41.479 --> 00:19:43.940 Beyond this range, the cosine value becomes negative 311 00:19:44.485 --> 00:19:48.286 Since the magnitude of a vector is never negative 312 00:19:48.286 --> 00:19:52.105 when the dot product of two vectors yields a positive result 313 00:19:52.319 --> 00:19:55.680 it indicates that the cosine of the angle is positive 314 00:19:55.924 --> 00:19:59.903 Conversely, if the dot product is negative, it signifies that the cosine of the angle is negative 315 00:20:00.319 --> 00:20:03.964 Therefore, if the dot product of the two vectors is positive 316 00:20:04.469 --> 00:20:08.109 it implies that the object is on the same side 317 00:20:08.109 --> 00:20:10.422 as the viewing direction 318 00:20:10.422 --> 00:20:12.180 which we describe as being in front 319 00:20:12.529 --> 00:20:16.540 On the other hand, if the dot product is negative 320 00:20:16.540 --> 00:20:18.829 it indicates that the object is on the opposite side, or behind 321 00:20:19.680 --> 00:20:22.739 This concept can be further applied 322 00:20:22.740 --> 00:20:25.980 to determine whether an object lies within a specific field of view 323 00:20:26.439 --> 00:20:29.440 Consider the following scenario 324 00:20:29.951 --> 00:20:33.510 Based on the direction you’re facing 325 00:20:33.511 --> 00:20:39.332 the angle between your line of sight and the target object is called alpha 326 00:20:39.673 --> 00:20:44.800 You can use this to check 327 00:20:45.301 --> 00:20:49.400 whether alpha falls within 328 00:20:49.400 --> 00:20:51.987 a predefined viewing angle, beta 329 00:20:52.119 --> 00:20:57.023 The field of view is typically defined symmetrically 330 00:20:57.024 --> 00:20:59.193 around the viewing vector 331 00:20:59.393 --> 00:21:03.886 so half of the field of view on one side is beta divided by 2 332 00:21:05.368 --> 00:21:09.637 The task is to determine whether the target lies 333 00:21:09.638 --> 00:21:14.172 within this range, meaning whether alpha is 334 00:21:14.172 --> 00:21:15.929 less than beta divided by 2 335 00:21:16.213 --> 00:21:21.121 If the object is detected within the field of view, it means alpha is smaller than beta divided by 2 336 00:21:21.598 --> 00:21:25.298 However, while the field of view beta is known 337 00:21:25.299 --> 00:21:27.894 the specific value of alpha may not be readily available 338 00:21:27.894 --> 00:21:28.760 and needs to be calculated 339 00:21:29.134 --> 00:21:32.074 To measure the angle 340 00:21:32.074 --> 00:21:37.919 one could use inverse functions such as the arctangent 341 00:21:38.259 --> 00:21:40.322 However, using the dot product is a more efficient way 342 00:21:40.322 --> 00:21:43.956 to determine whether an object lies 343 00:21:43.957 --> 00:21:46.444 within the field of view without needing 344 00:21:46.757 --> 00:21:48.817 to calculate the actual angle alpha 345 00:21:50.520 --> 00:21:52.110 Here’s how it works 346 00:21:52.111 --> 00:21:55.841 First, precompute and store the value of cosine of beta divided by 2 347 00:21:55.841 --> 00:21:57.439 Since the field of view 348 00:21:58.822 --> 00:22:02.782 for a character typically doesn’t change often 349 00:22:03.040 --> 00:22:07.834 precomputing and storing this value is advantageous 350 00:22:08.312 --> 00:22:11.352 Next, normalize both the viewing vector and 351 00:22:11.353 --> 00:22:13.658 the vector pointing toward the target 352 00:22:13.658 --> 00:22:16.873 Normalization ensures that both vectors have a magnitude of 1 353 00:22:17.488 --> 00:22:22.381 When these normalized vectors are dot-multiplied 354 00:22:22.382 --> 00:22:24.362 the result is the cosine of alpha, the angle between them 355 00:22:25.112 --> 00:22:28.111 Due to the properties of the cosine function 356 00:22:28.872 --> 00:22:31.672 its value decreases as the angle increases from 0 357 00:22:31.672 --> 00:22:34.640 all the way to 180 degrees 358 00:22:34.900 --> 00:22:35.620 All the way down 359 00:22:35.621 --> 00:22:41.832 The cosine function decreases in value as the angle increases 360 00:22:42.199 --> 00:22:46.190 Therefore, if the cosine of alpha is greater than 361 00:22:47.593 --> 00:22:52.372 the cosine of beta divided by 2 362 00:22:52.373 --> 00:22:54.933 it means the angle alpha is smaller than that 363 00:22:55.191 --> 00:22:57.644 By comparing the two cosine values 364 00:22:57.645 --> 00:23:01.651 if the cosine of alpha is greater than the cosine of beta divided by 2 365 00:23:02.322 --> 00:23:05.942 we can determine that the target is within the field of view 366 00:23:06.336 --> 00:23:09.356 even without calculating the exact angle 367 00:23:09.800 --> 00:23:15.443 While inverse functions can sometimes be used 368 00:23:15.443 --> 00:23:19.352 leveraging the properties of the dot product 369 00:23:19.353 --> 00:23:23.492 is far more efficient and practical for this purpose 370 00:23:24.492 --> 00:23:27.664 Next, let’s look at shading calculations 371 00:23:27.934 --> 00:23:30.453 In computer graphics, particularly in 3D rendering 372 00:23:30.913 --> 00:23:35.493 the direction of light significantly 373 00:23:35.767 --> 00:23:36.900 influences shading 374 00:23:36.900 --> 00:23:42.681 The dot product is an essential tool here 375 00:23:43.241 --> 00:23:46.054 When there is a light source 376 00:23:48.120 --> 00:23:52.581 the light strikes a surface, reflects off it 377 00:23:53.743 --> 00:23:56.523 and eventually reaches our eyes 378 00:23:56.900 --> 00:24:01.460 The amount of light illuminating the surface 379 00:24:01.923 --> 00:24:07.823 is maximized when the surface is oriented perpendicular 380 00:24:08.479 --> 00:24:10.302 to the direction of the incoming light 381 00:24:10.895 --> 00:24:15.834 As the angle between the light direction 382 00:24:17.459 --> 00:24:19.719 and the surface normal increases 383 00:24:19.720 --> 00:24:23.595 the amount of incoming light gradually decreases 384 00:24:23.595 --> 00:24:25.559 This decrease is 385 00:24:25.559 --> 00:24:32.458 directly proportional to the cosine of the angle between them, described in Lambert’s Cosine Law 386 00:24:32.458 --> 00:24:37.998 Shading is determined based on the cosine of the angle 387 00:24:37.998 --> 00:24:39.315 between the surface normal and the light direction 388 00:24:39.315 --> 00:24:42.541 This simple formula allows shading to be efficiently calculated using the dot product 389 00:24:42.542 --> 00:24:44.541 To apply this, first, calculate the surface normal vector 390 00:24:44.541 --> 00:24:47.591 and the vector pointing from the surface to the light source 391 00:24:47.940 --> 00:24:53.461 Normalize the light vector so that its magnitude becomes 1, then compute the dot product between the two vector 392 00:24:53.461 --> 00:24:57.689 The result determines how much light is hitting the surface 393 00:24:57.829 --> 00:25:01.469 and serves as a key factor in defining the shading 394 00:25:02.349 --> 00:25:05.701 The surface normal vector is typically denoted as N 395 00:25:05.701 --> 00:25:10.328 and the vector pointing from the surface to the light source is labeled as L 396 00:25:10.328 --> 00:25:12.581 It's commonly paired as N.L 397 00:25:12.870 --> 00:25:17.020 This basic formula for shading is 398 00:25:17.021 --> 00:25:20.996 derived from Lambert’s Cosine Law 399 00:25:20.997 --> 00:25:23.077 and is the foundation for what is commonly called a diffuse shader 400 00:25:23.077 --> 00:25:27.621 For example, in game engines like Unity 401 00:25:27.622 --> 00:25:30.728 a diffuse shader utilizes this principle 402 00:25:30.728 --> 00:25:33.394 to define surface illumination 403 00:25:33.734 --> 00:25:39.516 based on the angle between the light 404 00:25:39.516 --> 00:25:40.821 That's the gist of this 405 00:25:40.821 --> 00:25:45.993 The N.L term represents 406 00:25:46.353 --> 00:25:48.463 the most fundamental lighting model 407 00:25:48.463 --> 00:25:51.100 and serves as the building block 408 00:25:51.101 --> 00:25:56.518 for more complex lighting calculations 409 00:25:57.359 --> 00:26:01.920 All you need to understand for now 410 00:26:01.920 --> 00:26:04.182 is that this N.L is at the fundamental level 411 00:26:04.920 --> 00:26:08.301 Lastly, I’ll explain the projection vector formula 412 00:26:08.501 --> 00:26:11.181 This formula is used 413 00:26:11.182 --> 00:26:12.562 to determine the projection 414 00:26:12.562 --> 00:26:14.679 of one vector onto another 415 00:26:14.679 --> 00:26:17.424 This formula comes handy in getting that 416 00:26:17.844 --> 00:26:20.285 When you have two vectors, u and v 417 00:26:20.960 --> 00:26:24.279 and you project u onto v, the resulting vector 418 00:26:24.496 --> 00:26:26.875 is what I’ll call v' 419 00:26:26.875 --> 00:26:32.064 This v' is the projection onto v 420 00:26:32.384 --> 00:26:34.486 So it is aligned in the same direction as v 421 00:26:34.486 --> 00:26:35.663 but with a different magnitude 422 00:26:36.175 --> 00:26:38.355 Different magnitude, same direction 423 00:26:38.923 --> 00:26:42.933 To calculate v’ 424 00:26:42.934 --> 00:26:45.325 since the direction is the same and the magnitude different 425 00:26:45.325 --> 00:26:49.155 we first need to normalize v 426 00:26:49.155 --> 00:26:52.315 By normalizing it, we get this v-hat 427 00:26:52.315 --> 00:26:55.291 Create a unit vector v-hat with a magnitude of 1 428 00:26:55.303 --> 00:27:01.105 Then, by multiplying v-hat by the magnitude of v’ 429 00:27:01.105 --> 00:27:03.971 we can determine v’ 430 00:27:04.904 --> 00:27:09.225 But how do we calculate the magnitude of v’? 431 00:27:09.485 --> 00:27:12.316 How do we get its norm? 432 00:27:12.864 --> 00:27:14.205 That's the question here 433 00:27:14.205 --> 00:27:17.185 Since we know what u is 434 00:27:17.730 --> 00:27:26.089 he magnitude of v’ can be found by multiplying the magnitude of u 435 00:27:26.089 --> 00:27:28.703 by the cosine of the angle, cos(theta), between u and v 436 00:27:29.123 --> 00:27:35.963 So, how do we calculate cos(theta)? 437 00:27:36.163 --> 00:27:41.463 Cos(theta) can be determined using the dot product 438 00:27:41.823 --> 00:27:45.025 Revisiting the dot product equation 439 00:27:45.026 --> 00:27:50.128 u dot v is equal to the magnitude of u times 440 00:27:50.129 --> 00:27:51.642 the magnitude of v times cosine of theta 441 00:27:51.998 --> 00:27:54.066 The cosine of the angle between them, cos theta 442 00:27:54.066 --> 00:27:57.465 can ultimately be rewritten and calculated 443 00:27:57.466 --> 00:27:58.714 using this formula 444 00:27:59.264 --> 00:28:03.405 Now, if we substitute this value back into the equation 445 00:28:05.721 --> 00:28:06.721 and multiply them together 446 00:28:07.684 --> 00:28:10.465 we can derive the final formula for the projection vector 447 00:28:10.465 --> 00:28:11.415 This v' 448 00:28:11.706 --> 00:28:13.826 The final projection vector is now here 449 00:28:14.364 --> 00:28:19.025 Here, for the dot product u dot v 450 00:28:19.495 --> 00:28:23.194 the denominator consists of the magnitude of u by that of v 451 00:28:24.444 --> 00:28:28.125 For v-hat, the denominator is the magnitude of v 452 00:28:28.125 --> 00:28:29.537 and the numerator is v 453 00:28:29.751 --> 00:28:34.290 Since the magnitude of v is used twice 454 00:28:34.291 --> 00:28:36.503 the result becomes the square of the magnitude of v 455 00:28:36.503 --> 00:28:39.224 Therefore, the expression can be written as u.v.v 456 00:28:39.651 --> 00:28:42.290 Since the numerator and denominator involve u 457 00:28:42.870 --> 00:28:44.910 any overlapping terms will cancel out 458 00:28:44.910 --> 00:28:46.644 The final formula for the projection vector is as follows 459 00:28:46.975 --> 00:28:48.935 The square of the magnitude 460 00:28:48.936 --> 00:28:51.893 is equivalent to the result of multiplying the same vector by itself twice 461 00:28:51.893 --> 00:28:53.864 so it can also be expressed as this 462 00:28:53.864 --> 00:28:56.069 Both are considered identical expressions 463 00:28:56.604 --> 00:29:00.961 If the magnitude of the vector v being projected onto is 1 464 00:29:00.962 --> 00:29:03.122 there is no need to calculate the magnitude 465 00:29:03.397 --> 00:29:06.677 and the formula simplifies further 466 00:29:07.203 --> 00:29:11.505 Now, this projection vector formula 467 00:29:11.835 --> 00:29:16.515 is significantly utilized in various vector applications 468 00:29:16.515 --> 00:29:20.903 and theoretical aspects, such as equations of planes 469 00:29:20.903 --> 00:29:22.903 and other mathematical theories 470 00:29:23.503 --> 00:29:29.225 For now, I’ll explain that this basic formula exists 471 00:29:29.226 --> 00:29:33.486 and I’ll provide a more detailed explanation of its applications 472 00:29:33.486 --> 00:29:35.856 later when we discuss plane equations 473 00:29:36.518 --> 00:29:39.125 This was on dot product 474 00:29:39.225 --> 00:29:41.305 This concludes today's lecture 475 00:29:41.305 --> 00:29:43.152 Thank you for listening 476 00:29:43.153 --> 00:29:44.113 Thank you 477 00:29:44.532 --> 00:29:45.832 Concept of Vector Dot Product Vector Dot Product Multiplying corresponding components and then summing them 478 00:29:45.833 --> 00:29:46.833 Properties of the dot product: Satisfies the commutative property, Not satisfy the associative property, Satisfies the distributive property (a,b)x(c,d)=ac+bd 479 00:29:46.834 --> 00:29:47.834 The dot product of the same n-dimensional vector results in the square of its norm 480 00:29:47.835 --> 00:29:49.503 Cosine Formula of the Dot Product axb=vector a x vector b x cosine theta When the magnitudes of two vectors are 1, scalar a x scalar b = cosine theta 481 00:29:49.503 --> 00:29:50.983 Concept of vector inner product Determining orthogonality of vector inner product You can prove that two vectors are orthogonal by the inner product 482 00:29:50.983 --> 00:29:51.845 (cos(theta), sin(theta)) dot (-sin(theta), cos(theta)) equals to 0 483 00:29:51.845 --> 00:29:52.985 Rigid transformation A transformation that maintains the shape of an object Rotation transformation does not change the shape of an object 484 00:29:52.985 --> 00:29:54.485 485 00:29:54.485 --> 00:29:55.426 Applications of the Dot Product Front-Back Determination If the dot product of two vectors is positive, the object is in front 486 00:29:55.427 --> 00:29:56.647 If the dot product is negative, the object is behind the viewing direction 487 00:29:56.647 --> 00:29:57.668 Field of View Check The inner product of the line of sight vector and the vector to the target is cosine alpha If the value of cosine alpha is greater than beta over cosine 2, the target is in the field of view 488 00:29:57.668 --> 00:29:58.589 Shading Calculation Lambert’s Cosine Law: The brightness of light reflected is proportional to cos angle between surface and light direction 489 00:29:58.589 --> 00:29:59.451 Shader Lighting Equation N.L The normal vector of the surface in space (N) The vector pointing from the surface to the light source (L) 490 00:29:59.451 --> 00:30:02.522 Projection Vector Formula Finding a vector projected onto another vector 491 00:30:02.522 --> 00:30:04.263 When the magnitude of the vector being projected is 1, vector v’ is u dot v multiplied by v