
Gamedev Tutorial: Dot Product, Rulers, and Bouncing Balls - cjcat2266
https://www.allenchou.net/2020/01/dot-product-projection-reflection/
======
mrspeaker
"The dot product is a simple yet extremely useful mathematical tool. It
encodes the relationship between two vectors’ magnitudes and directions into a
single value. It is useful for computing projection, reflection, lighting, and
so much more."

I wish every programming and math tutorial started with a paragraph like this!
So many times I get to the bottom of an article on a concept with an
understanding of _how_ to implement it, but no idea _why_ I'd want to!

~~~
Waterluvian
Game dev is also a fantastic practical application.

I struggled awfully through high school math. Then a decade later I went to go
make a space shooter. I learned so much more vector math and trig in like two
weekends than all of high school.

~~~
Mirioron
To expand further: you can use anything you've ever learned in gamedev. All of
it can be useful. From physics, chemistry, biology to languages, trivia,
culture etc. But what I find even more fascinating is what players of games
can do with just a simple system.

------
Const-me
The ball motion formula is less than ideal. Can be much more precise, for very
small extra performance cost:
[https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm](https://en.wikipedia.org/wiki/Leapfrog_integration#Algorithm)

~~~
meheleventyone
Semi-implicit Euler as shown in the ball example is pretty common and usually
good enough. Leapfrog has other issues with the decoupling of velocity and
acceleration. For example adding in the effects of drag or anything else where
the acceleration is dependent on velocity.

~~~
Const-me
> and usually good enough

Usually, but for the OP's bouncing balls conservation of energy would be nice.

Another thing, "good enough" is a moving target, both games and the hardware
running them improve over time.

------
adamnemecek
I know this is tangential but my fav definition of inner and outer products is

Inner(x,y) = x'.y

And

Outer(x,y) = x. y'

' is adjoint

~~~
IIAOPSW
My favorite is

inner: <bra|ket> outer: |ket><bra|

~~~
japanuspus
As a quantum physicist who has drifted into other fields, I keep returning to
bra-ket [0] notation when I have to do any linear algebra calculations. Find
it to be the most ergonomic notation for linear algebra, especially in product
spaces.

In my experience, the key to avoiding snickers from math-types when using bra-
kets is to say "dual space" [1] a couple of times.

[0]:
[https://en.wikipedia.org/wiki/Bra%E2%80%93ket_notation](https://en.wikipedia.org/wiki/Bra%E2%80%93ket_notation)

[1]:
[https://en.wikipedia.org/wiki/Dual_space](https://en.wikipedia.org/wiki/Dual_space)

------
hazz99
This an extremely well-written tutorial! I love it, especially from someone
from a weaker math background.

