1. Vector - Basics (2D)
Points
Notation
Let P =
Mid point
Distance
Vectors
Let
Length
Dot product (Info)
If dot product > 0, angle between
If dot product = 0, angle between
If dot product < 0, angle between
Why? Because of the
Angle between 2 vectors
Special cases
| Dot product result | Angle |
|---|---|
| -1 | |
| 0 | |
| 1 |
For dot product 1 and -1 NEED to be unit vectors. For dot product 0, it doesn't matter
Checking if vectors are parallel/perpendicular
For parallel
For perpendicular
See Dot product, Special cases
Making a normal vector
In 2 steps:
- Swap
and - Negate either the
or - Negate
to rotate anti-clockwise - Negate
to rotate clockwise
- Negate
Vector Projection (Info)
Project
General:
If
Checking if moving towards a point
Only 1 point moving
Get a vector
Find
At
At
At
2 points moving
Assume P is stationary **relative** to Q #todo-low
Imagine P and Q are cars at a intersection. And you are sitting in car P.
From my perspective, Car Q moves towards me relative to my (Car P) current speed.
Checking if a moving point will hit line
| Hit | Miss |
|---|---|
| Hit if the signs of these 2 are different |
Or in code: