lesson

Updated 1 month ago Β· 5 views
How do 3D video game engines know if a player's line of sight is at an exact right angle to a wall?
Instead of measuring angles with expensive trigonometry, graphics software uses a single multiplication trick: the scalar product.
πInteractive diagram
To see why this test works, let's look at how the scalar product connects geometry to algebra.
The Perpendicularity Condition
The scalar product (or dot product) between two non-zero vectors a and b is defined geometrically as aβ
b=β£aβ£β£bβ£cosΞΈ, where ΞΈ is the angle between them.
In the 1880s, American physicist Josiah Willard Gibbs developed this product to simplify complex electromagnetic equations into simple component algebra.
When two vectors are perpendicular (at an angle of ΞΈ=90β), the cosine of the angle becomes cos(90β)=0.
Because β£aβ£ξ =0 and β£bβ£ξ =0, the formula gives aβ
b=β£aβ£β£bβ£(0)=0.
πInteractive diagram
What happens when we compute this using coordinates in three dimensions?
Testing 3D Vectors
In component form, you calculate the scalar product by multiplying matching components and adding the results: aβ
b=axβbxβ+ayβbyβ+azβbzβ.