6.5: Vectors: Dot Product and Scalar Projection - The Nature of Code

  Рет қаралды 40,573

The Coding Train

The Coding Train

Күн бұрын

This video provides an overview of the formula for and applications of the vector dot product. It covers scalar projection. It serves as the basis for the next video about Path Following.
Read along: natureofcode.com/book/chapter-...
More info: en.wikipedia.org/wiki/Dot_product
Code from video:
github.com/shiffman/The-Natur...
github.com/shiffman/The-Natur...
Help us caption & translate this video!
amara.org/v/Qbvg/
📄 Code of Conduct: github.com/CodingTrain/Code-o...

Пікірлер: 54
@kyle-bensnyders3147
@kyle-bensnyders3147 7 жыл бұрын
I laughed out loud when you said "I wish I had a kitten. Pet the kitten". Never have I been so entertained and educated at the same time. Been watching your videos for a while now. There are so many! I want to thank you so very much for them. They are helping a lot not only with web development (for visual effects), but also game development, and just generally becoming a more well rounded person. THANK YOU!
@mihreteabgirma6351
@mihreteabgirma6351 3 жыл бұрын
Sir this is amazing, I studied about 75% of ur videos topic but for the fact I loved the way you explained I just watched the whole video (Clear!) THANK YOU♤♡
@Kno3Breakfast
@Kno3Breakfast 7 жыл бұрын
Thanks for the great videos. It's rare to see someone actually explains the logic and process behind the code. Can't tell you enough how much I appreciate your videos. Keep it up!
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
Thanks for the nice feedback!
@sophiekim5105
@sophiekim5105 Жыл бұрын
I learned vectors and trigonometric functions again 12 years after graduating from high school to understand your lecture. Thanks for the good class!
@corey333p
@corey333p 7 жыл бұрын
You explained very clearly how to calc the dot product, but I didn't feel like I really "got it" until I came across this: "The dot product tells you what amount of one vector goes in the direction of another." It makes more intuitive sense when explained like that. You might've made that clear, but I missed it. In any case, maybe it will help someone!
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
Thanks for this useful feedback!
@alvarorodriguez7076
@alvarorodriguez7076 7 жыл бұрын
corey333p that made it sooo much clear!! Thanks
@ulaptoptrekker
@ulaptoptrekker 4 жыл бұрын
I have been struggling til this comment. Thank you
@Brahvim
@Brahvim Жыл бұрын
Just adding a little more!: There actually are 'minimum' and 'maximum' values for the dot product! They're `-1` and `+1`. This makes sense. The dot product should be `-1` if the vectors are _just_ opposite to each other, and `+1` if they're both _completely_ equal.
@p_2923
@p_2923 2 жыл бұрын
bruh your grasp of this topic must be so fundemental to you b/c you explained this so fucking well. Cheers brother you helped a struggling physics student.
@peterhayman
@peterhayman 6 жыл бұрын
ooohhh maaan i just realized, this is the weatherman technique!! i swear for some reason it super helps to have an educator physically pointing at the computer, body language is very valuable, nice one dan :-)
@MrBostich83
@MrBostich83 8 жыл бұрын
You should have a million views. Perfect videos, really well done!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+MrBostich83 thanks so much!
@Jai_Lopez
@Jai_Lopez 8 жыл бұрын
+MrBostich83 more like a million dollars
@justcore69
@justcore69 10 ай бұрын
Ah, it was such an interesting, informative, and cozy lecture. I like it :)
@franeklubi
@franeklubi 5 жыл бұрын
God, I love you Dan, thanks for all the tutorials
@ahmedelzeiny7394
@ahmedelzeiny7394 Жыл бұрын
Angle of a vector is also atan2(vy, vx); which is useful because we generally want to avoid sqrts in our gaming code
@frateantudor5761
@frateantudor5761 7 жыл бұрын
This explanations were super clear. Thank you!
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
Thanks!
@MrEstebanEscudero
@MrEstebanEscudero 4 жыл бұрын
Just excellent explanation! Great video
@vibhatha
@vibhatha 5 жыл бұрын
Great explanation. Really enjoyed it.
@paularojas9852
@paularojas9852 3 жыл бұрын
So well explained and super funny, thank you so much for this video!!!
@Diotallevi73
@Diotallevi73 11 ай бұрын
3:39 Beads, flowers, freedom, happiness 🎉
@cavalfou
@cavalfou 4 жыл бұрын
Holy cow, sir, thanks !!!!
@dominiksmeda7203
@dominiksmeda7203 5 жыл бұрын
I love your channel
@markgohl2660
@markgohl2660 5 жыл бұрын
Thanks very useful :)
@Mrelevatorman
@Mrelevatorman 7 жыл бұрын
All your videos are first rate. Thank you so much for making them. I have one questions. How can I use the dot product to determine whether the angle relative to my current vector is negative or positive with respect to the vector I'm comparing it with? Thanks again.
@toastyPredicament
@toastyPredicament 2 жыл бұрын
I just sold my soul to obtain those.
@carlosyeverino3317
@carlosyeverino3317 3 жыл бұрын
Thanks for sharing your knowledge and high content quality videos, sir! I still have one question regarding the vector dot product. I'm trying to perform an orthogonal projection for two points S1 and S2 into an estimated line with the model Ax + By + C = 0. This line was estimated by the least-square method considering a set of points whose start and end points are the points that I want to project to the line (S1 and S2). My approach was to get two points P1 and P2 that lie on the line by providing the x coordinates of the start and end points to the model equation in order to predict the corresponding y coordinates. Then, I computed the vector from P1 to P2 which has the same direction as the line. I normalized the obtained vector to get its unit vector. Moreover, I computed the vectors from P1 to S1 and P1 to S2. Finally, I performed the projections: ProjP1 = (vector P1-S1 dot product unit vector) * unit vector + P1 and ProjP2 = (vector P1-S2 dot product unit vector) * unit vector + P1. However, I am not obtaining orthogonal projections. Do you have any idea how to correctly perform an orthogonal projection for a point into an estimated line with the model Ax + By + C = 0??
@musakaratu2050
@musakaratu2050 7 жыл бұрын
Brilliant presentation. Could you please help me with the code for 3D flow field. Thank you
@guruprasanna4801
@guruprasanna4801 2 жыл бұрын
I wish my math teacher teach me like this.
@croncoder862
@croncoder862 2 жыл бұрын
brilliant
@christianjt7018
@christianjt7018 5 жыл бұрын
Awesome
@MrMytubevidmaker
@MrMytubevidmaker 4 жыл бұрын
Why are you still multiplying with b at the end? Isn't A.dot(B) enough if B is normalized?
@oldleaf3755
@oldleaf3755 2 жыл бұрын
ok thanks
@anilaxsus6376
@anilaxsus6376 5 жыл бұрын
I would like you to rename this video, or add the sentence "Scaler Projection Explained" :) I have been looking for an explanation for it.
@TheCodingTrain
@TheCodingTrain 5 жыл бұрын
Thanks for the note!
@MarkusBurrer
@MarkusBurrer 7 жыл бұрын
Does this code also works for 3d vectors? Or how can I calculate the scalar projection for 3d vectors?
@odonflanagan9219
@odonflanagan9219 7 жыл бұрын
Yeah, ax*bx + ay*by + az*bz. for a 3d vector(x,y,z)
@p_2923
@p_2923 2 жыл бұрын
Cross product
@jaymeekae84
@jaymeekae84 3 жыл бұрын
This video is a brilliant explanation but the code visible at 7:10 doesn't seem to work, and the code linked on github just uses angleBetween(). I think that vector a and b need to be normalised before using the formula to calculate the angle, otherwise d/(a.mag() * b.mag) produces a number greater than 1... so the acos function then produces NaN.
@jaymeekae84
@jaymeekae84 3 жыл бұрын
Wait and then this means that surely you can just do acos(d)... because the magnitude of a and b are both 1. This seems to work.
@RedEyedJedi
@RedEyedJedi Жыл бұрын
If we could just clone Daniel and fill up our schools with Daniels for every lesson the future would be very bright indeed.
@hago7568
@hago7568 5 жыл бұрын
after watching the latter part of the video for the 25th time about projections I also wish I had a kitten.
@tmrmbx5496
@tmrmbx5496 4 жыл бұрын
Hello legend
@Brahvim
@Brahvim Жыл бұрын
"You know, I am just locked in a room... with lights... and Processing, [so what else am I supposed to do...?]" Aren't we all? 😂
@TheCodingTrain
@TheCodingTrain Жыл бұрын
I am amazed that people are still watching these videos from 10 years ago!
@Jai_Lopez
@Jai_Lopez 8 жыл бұрын
another great video dan , useful sketch thanks now i have to ask, what determines how the vectors are setup in github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp06_agents/FlowfieldImage in there you have 3 photos which give diff outcomes, how and why dan? further more i imported my own pic just to test something out and i got diff vectors then all others so what is it that tells vector how and or where to setup shop? more specifically how do i get the vectors to follow this road but not that road? how do i tell vectors to change their magnitud of speed if a condition is met? i see in you face.jpg in the data folder that the vectors are following the face profile pretty good but this is the only photo that vectors line up so neat following that contour that makes up the face , pretty cool dan
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+jai Lopez The vectors point in a direction based on the brightness of pixels in the image. You can see this in this line of code (github.com/shiffman/The-Nature-of-Code-Examples/blob/master/chp06_agents/FlowfieldImage/FlowField.pde#L40). It's an arbitrary demonstration of the idea of mapping pixels to vectors in a flow field. If I were to improve it I might have the vectors point in a direction based on neighboring pixel brightness.
@toastyPredicament
@toastyPredicament 2 жыл бұрын
This may blow your mind but p5.js etc isn't the only JS thing out there
@kimhunter4119
@kimhunter4119 6 жыл бұрын
learn how to make a number 2
@c.s.842
@c.s.842 3 жыл бұрын
You represent everything I despise about maths teachers. Self indulgent show offs, all speeded up, with no regard for the alumni. Calm down, tone down you ego, stop giggling and do keep sharing your knowledge. Thanks
6.6: Steering Behaviors: Path Following - The Nature of Code
21:35
The Coding Train
Рет қаралды 46 М.
The real world applications of the dot product
12:49
Zach Star
Рет қаралды 213 М.
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 37 МЛН
Final muy inesperado 🥹
00:48
Juan De Dios Pantoja
Рет қаралды 10 МЛН
Watermelon Cat?! 🙀 #cat #cute #kitten
00:56
Stocat
Рет қаралды 25 МЛН
1.1 What is a Vector? - The Nature of Code
15:43
The Coding Train
Рет қаралды 127 М.
Everything You Need to Know About VECTORS
17:42
FloatyMonkey
Рет қаралды 1 МЛН
Cross Product and Dot Product: Visual explanation
4:08
Physics Videos by Eugene Khutoryansky
Рет қаралды 949 М.
Vector Projections | Vector Calculus #17
5:17
Bari Science Lab
Рет қаралды 41 М.
The meaning of the dot product | Linear algebra makes sense
13:04
Looking Glass Universe
Рет қаралды 73 М.
Work as the Dot Product
15:11
Flipping Physics
Рет қаралды 9 М.
What's a vector projection?
4:27
Joel Speranza Math
Рет қаралды 25 М.
1.1: Vectors - The Nature of Code
9:50
The Coding Train
Рет қаралды 147 М.
Every Weird Math Paradox
11:15
ThoughtThrill
Рет қаралды 6 М.
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 37 МЛН