The Dot Product - A Visual Explanation
Вставка
- Опубліковано 4 сер 2019
- 🔽 Click
Clipped from the super long shaders for beginners stream of two days ago!
Note that this is for two normalized vectors, it's a bit different if only one or none of them are normalized. Regardless - the case of two normalized vectors is very common in shaders!
For example, Lambert shading is the dot product of the light direction and the surface normal
Full video will be up soon!
📺 Twitch ❱ / acegikmo
🐦 Twitter ❱ / freyaholmer
💬 Discord ❱ / discord
🌸 Instagram ❱ / freya_holmer - Наука та технологія
This video is literally that meme where "the random youtuber with a small channel has the exact answer to your problem"....Even the bigger channels didn't explain the concept behind dot products so simply. Love this!
wtf who hasnt explained dot products is the question... and its not even a good explaination... The forgot to mention many but its ok for people who dont need to understand what the dot product really is.. In fact its the worst explaination but ok for casuals..
You wouldn't believe how helpful your videos have been for me. Studying games programming and I have a maths module. Your videos have totally saved my life! Thank you so much.
this is so cool and useful Freya! I have been working with shaders for a long time but the bigger my mental library gets the more I need to study in order to keep my knowledge. Videos like these are super helpful for this.
In just over a minute you explained to where it finally made sense. Nice!!
This is actually such a good video. I've been struggling so long to understand this thank you so much!!
brilliant explanation, thank you so much for the simple illustration
Far and away the best explanation I've come across. People normally try to make it sound complex but it's not.
made my day. happy to find your channel
Great video! I appreciate how concise this was!
Wow this explanation is crazy intuitive, thank you so much
"Ugh this is doing my head in, I hope there's some Freya-like explanation on YouTu--" AND THERE IT IS
Visual explanations are very cool and useful, thank you)
Clear and sharp ! Thank you !
Awesome explanations, made so simple. Thank u
Thank you for sharing your explanation the of the Dot Product. Helped a lot =D
Thanks a lot🎉
Such a good explanation
This actually makes perfect sense! Now i perfectly understand how dot products work in my code
As someone with chronic migraine, which makes thinking about and understanding complicated concept really hard, your explanations are a blessing.
literal math mommy.
thank you
Keep up the good work!
Ty so much for the visualization, i was having a hard time understanding from everyone's explainations
just solved my problems in about 45 seconds thank you!
you are a live saver!
The explanation has to be qualified as it is correct iff the first vector is a unit vector. Or, the dot product would be the projected distance x the length of first vector. Actually, it would be nice to start with a unit vector, then generalize into non-unit vectors. Overall, this is a concise explanation.
can you explain why its only right for a "unit vector" ? Just starting to understand vectors myself.
@@MathCuriousity its because the dot product of two vectors is the length of the projected vector multiplied by the length of the vector it was projected onto, the video "Dot products and duality" by 3blue1brown explains this in a lot more detail
@@redact7395 hmm ok and why did another person say it was only ok for normed?
@@MathCuriousity this video applies as long as the vector you are projecting onto has a length of 1 and unit vector and a normalized vector just mean that the vector has length 1
most important, not forget normalize both vectors before sending them to dot product, just in case. I had bad results when not normalized, scratched my head before realize why that happened.
only one must be normalized
what i understand is that, when we want to compare the angle diferences we normalise both the vector, and if we wanted to compare the magnitude or the length or distance, then dont need to normalise it, mean one is the compare angle the other is to compare distance or range
@@Mj-multimediaNet Depends what you want to do. Sometimes you want then not normalized. Sometimes you want only one of them normalized. And sometimes yoy want them both normalized.
In this specific case you want to find cosine of an angle. So both of them should be normalized.
What does “normalize” mean? Was she showing “normalized”?
What does normalize mean
man, whenever im trying to understand some game dev math stuff i really should come to this channel first
Amazing!
Muchas gracias. Gran Explicacion
Am a senior engineering student and never quite thought about it this way. Props!
ur vibe is so cool
Thank you so much!
Finally someone explaining what the dot product even is instead of just jumping into how it is calculated.
Thank you for your video!!
Damn, i have seen hours long videos on dot product! When you know, you know! Thanks Freya..
Thank you!
Very helpful, thanks a lot
Very helpful video!
Really good explanation. Even a simpleton like myself understood it :)
some who says simpleton is not simple
Best Teach for Game math
short and usefull thank you !
is it basically cosine of the angle in between two vectors
Woah! Very useful
I wish I could tick a "love" emoji instead of just like. Most concise explanation I've found so far.
if I've more teachers like you in college
thiss was peerfect
Thanks a lot !!
NICE!
Im going to use this to confirm if my bots are facing their target's before they can attack within a FoV!
Very simple.huge useful.
This is the best explanation for it lol
damn, that a pro explanation 1m and I understood perfectly lol
short n sweet good 4 students
Nice
thanks
wow this explained it really fast
I'm sorry if this come off as a dumb question, i'm not really good with math,
For this to work rightly the 2 vectors must stem from the same origin right ?
yes! but also, vectors technically don't "have an origin", they're always only the tip, in terms of the data stored
great video! What about non-normalized vectors?
for anyone whos wondering: if you normalize one of them, you can calculate the length of the non normalized vector, because its basically checking "how often does it fit into the normalized vector (length 1) if you projected it?"
Only if the module of both vectors are 1... Cuz dot product is a product of 'the parallel part of b in respect to a' and a
enjoyablllle
@Freya what does "normalized" vector mean that she talks about in her description!?
A normalized vector has a unit "length", i. e. it's a vector divided by its norm equal to itself.
@@edcify8241what would that be as an equation?
@@MathCuriousity The normalization of a vector α is α'=α/||α|| (scalar multiplication by the reciprocal of its norm), and a vector is normalized iff α'=α.
i said to myself, "i know she'll explain this to me" and you did
In a 3D scene, when i.e. calculating if an enemy is in front of the player, can we use the dot product to also check the vertical angle? Or is the dot product rather a flat circle instead of a sphere?
it's always the dimension of the space it's in, so in 3D it would be like a hemisphere, so you wouldn't be able to distinguish vertical from horizontal (without more math), but you would still be able to do the, "facing away" check
@@acegikmo Thank you for the clarification, Freya!
now I understand how the hessian normal form works (you only normalize the normal vector in that one), thank you miss Freya!
a way that I love to use: to get projection: (vec1 * (1/sqrt(vec2 * vec2) * vec2) ) = scalar * (1/sqrt(vec2 * vec2) * vec2) ___ that works for 180 degree and you get it without use cos or sin, or 360 with some tricks
the cos and sin are to move the blackdot and are not connected how we calculate the tangent line.
www.geogebra.org/m/w3gnjwae (move B around the cercle )
a fast way to get tangent to a curve at any power : like for circle a projection of vP on unit vertical vector and we negate it . works for any value of x (power)
www.geogebra.org/m/cpsbdbyv (move tx)
the same in 3 D (partial derivative ....)
www.geogebra.org/m/jsfkkbpu (move ty and tx)
always with projection only
a gradient color pick with small maths and code
www.geogebra.org/m/fe4tyh2m
bye
and thanks for those videos :))
Lo
thanks mama
A dot product is taking two normalized vectors and taking the length from one's tip down to the other vector in a perpendicular direction to it.
So basically it's a projected vector clamped to one?
the dot product is not a vector. It is a scalar. Its just the value of "how much of one vector is contained in the other"
@@deyomash can I also say its "how much one vector opposes another" ?
@@MathCuriousity The dot product between two vectors gives a value that resembles the 'overlap' between the two. If its zero they don't "overlap" at all, which means they are perpendicular. If the dot product is simply the length of one of the two this means they are parallel. Everything else lies in between :)
Isn't that similar to cosine then, if this is on a unit circle?
yeah! the dot product is often defined using the cosine
@@acegikmo much thanks
if I've more teachers like you in college
Thats trigonometry
Really good explanation! Could you please tell me where this can be used at its best ? I've been asked at a lot of interviews about dot products but I've never really understood them enough to answer about it. Now that I do, thanks to you! It'd be really awesome to know where this dot product can be used.
In shaders, it can be used to tell if a normal is facing a light source or not. U can use the dot product to calculate how dark a pixel should be colored.
In regular game world, a dot product can be used to tell if a player is looking at an object or not.
fresnel effect, moss on top of a stone (though it could be rotated differently if you add another vector), PBR shaders reflection of fringes (almost same thing as fresnel, really), or to generate trees and grass only on non-sloped surfaces.
also hit detection of railguns, rocket launchers, etc.
In procedural 3D modeling, I can use the dot product to determine whether part of a curve is pointing in the right direction. Or to check which parts of a polyline are near horizontal or vertical. It's more useful than calculating the angle because the dot product gives only 1 value instead of both an inner and outer angle.
Given a Vector A and Angle, between Vector B.
How can we find the value of Vector B?
Vector A = (0,0,1). Angle can be any.
it's an underdetermined problem, because we can't know the length of B or what direction B is deviating in from A (two solutions in 2D, infinite solutions in 3D)
but, if you assume B has the same magnitude as A, and that the angle is signed rather than the shortest angle, it's a matter of rotating the vector A by the angle
@@acegikmo In my case, I have a Vector A which is basically Vector3.forward, (0,0,1).
I have another Vector B which is used as Direction of Wind. So, for example, I want to change the direction of wind to a certain angle.
I determine the angle by Vector3.Angle(VectorA,VectorB).
It returns me the angle based on Value of B whatever I change.
I want to turn Vector B in such a value that I get a desired Angle between the two.
I suck at trignometry, so I am just not being able to visualize things, and hence cannot put it in code.
I somehow managed to find some code within Unity something like this:
vector2 = Quaternion.AngleAxis(targetAngle, new Vector3(0,1,0)) * Vector3.forward;
I just saw this snippet and it worked. But I still am not able to comprehend it or how it works etc.
@@FaizanKhan-um6bn In 3D you need an axis to rotate around and if you want the result to be perpendicular to the original then that axis needs to be perpendicular to the original as well, so you're back to square one
What you have here doesn't work in all cases, only in cases where the Y coordinate of the vector A is 0 (because in the equation the axis of rotation has Y coordinate 1).
In fact it's impossibly to chose a vector that will work in all cases. One common trick that games use is to grab an arbitrary direction (eg: world up), then make a cross-product with the Vector A, then use the resulting vector (normalized ofc) as the axis of rotation
ie:
WorldUp = new Vector3(0,1,0);
RotAxis = Vector3.Normalize(WorldUp x VecA);
VecB = Quaternion.AngleAxis(targetAngle,RotAxis) * VecA; (we rotate VectorA around RotAxis by targetAngle radians)
But be aware that this creates two singularities where RotAxis is undefined, when VecA and WorldUp are the same, or exact opposite. At those times the cross product will create a vector of 0 length.
@@spliter88 Hey can you explain why people are saying her video is bad because she didn't normalize? what does normalize mean? Also can you explain like I'm five your video game analogy!
@@MathCuriousity I havent seen the video in a long time so you'd have to be more specific what's their exact problem, but my guess is at some point in the video she's saying the dot product between two vectors is the cosine of the angle between them.
Normalizing a vector just means turning it into a unit vector. So you just calculate its length and then divide that vector by the length.
In the case of cosine, the dot product beyween two vectors is only the cosine of the angle between them if both vectors are unit vectors (ie: normalized) otherwise it'll be cosine times the length of vector A times the length of vector B
Good explanation but just to mention, everything sad here is true under the assumption that those vectors are normalized which means their length is 1.
What about Z axis?
The dot product works in any number of dimensions. Just like the Pythagorean theorem.
@@edcify8241 aight, the video was about just 2D so I wasn't sure
that feel when you invented cos(x)
my fix was to normalize them...
i think you meant to say parallel hehehehheheeeeeee
Hi IRL sonic :D
lmaooo@@kaiandkoarivera7025
This is not quite accurate. In reality, u⋅v = magnitude of the projection of u unto v times the magnitude of v. she said that it is simply the magnitude of the projection of u unto v.
by the way, since u⋅v = v⋅u, it also works if you think : magnitude of the projection of v unto u times the magnitude of u.
yeah i was about to comment the same thing
is this because her vectors were not "normalized" whatever that means!?
@@MathCuriousity if she were to use normalized vectors, then she was right. because magnitude of v would be 1.
may i ask, when did you transition from MtF ?
im confused, but not at the topic
you are so beautiful , love you
search dot product game, get 1 minute 49 sec video....no regrets, thanks
You have sort of an Irish accent
if I've more teachers like you in college
She is a great teacher