This commit is contained in:
Schluffe
2026-09-04 13:57:52 +02:00
parent 71cfa64793
commit e961887953
24 changed files with 340 additions and 360 deletions
+6 -5
View File
@@ -9,7 +9,7 @@ An arrow `(x, y)` has a length: how far it reaches. Pythagoras:
### Normalize
Often you want *just the direction* of an arrow, with length exactly 1 (a "unit
Often you want _just the direction_ of an arrow, with length exactly 1 (a "unit
vector"). You get it by dividing the arrow by its own length:
`(x / len, y / len)`.
@@ -20,14 +20,15 @@ straight movement.
> ⚠️ **The zero-vector trap.** What is the length of `(0, 0)`? Zero. What is
> `0 / 0`? `NaN`. If you normalize a zero vector naively, you poison it with
> `NaN`, and `NaN` spreads through every later calculation silently. A correct
> `normalize` must check for zero length and return `(0, 0)` instead of dividing.
> Remember this trap — it is exactly the kind of bug that hides in a real engine.
> `normalize` must check for zero length and return `(0, 0)` instead of
> dividing. Remember this trap — it is exactly the kind of bug that hides in a
> real engine.
### Dot product
`dot(a, b) = a.x*b.x + a.y*b.y`. One number out of two vectors. For now just
implement it; in step 09 you'll learn that it answers "how much of arrow A points
along arrow B?" — the key to sliding along a wall.
implement it; in step 09 you'll learn that it answers "how much of arrow A
points along arrow B?" — the key to sliding along a wall.
## Task