Points and Vectors
A point says where something is; a vector says how to get from one place to another: a direction together with a distance. In both are written as lists of numbers, and the difference between them matters a lot in geometry and in graphics code.
: lists of numbers
is the set of all ordered -tuples of real numbers . For it is the plane, for ordinary space, and for larger it is just as useful even if we cannot draw it: a colour is a point in (red, green, blue), a grey-scale image is a point in , and an LLM token embedding is a point in or more.
In linear algebra a vector is usually written as a column:
The numbers are the components (or entries, or coordinates) of . Two vectors are equal when they have the same number of components and every component agrees.
From two points to a vector
Given points and , the vector from to is
It tells you how far to move in each coordinate direction to walk from to . Vectors have no fixed position: the arrow from to and the arrow from to are the same vector , drawn at two places.
y
4 | · Q'(7,4)
3 | ·──┘ P'(5,3) both arrows are the vector (2, 1)
2 |
1 | · Q(2,1)
0 · P ──┘
└──────────────────────── xThe vector from the origin to a point is the position vector of ; its components are the coordinates of . That is why the same list of numbers can describe either, and why it is easy to mix them up.
import numpy as np
P = np.array([1.0, 2.0, -1.0])
Q = np.array([4.0, 0.0, 3.0])
PQ = Q - P
print("vector P->Q:", PQ)
print("vector Q->P:", P - Q)
# moving point P by the vector PQ lands on Q
print("P + PQ =", P + PQ, " equals Q?", np.array_equal(P + PQ, Q))
# the same displacement applied at another point
R = np.array([10.0, 10.0, 10.0])
print("R + PQ =", R + PQ)vector P->Q: [ 3. -2. 4.]
vector Q->P: [-3. 2. -4.]
P + PQ = [4. 0. 3.] equals Q? True
R + PQ = [13. 8. 14.]
What makes sense
| Operation | Result | Meaning |
|---|---|---|
| vector | displacement between them | |
| point | move the point | |
| vector | combine displacements | |
| vector | stretch or reverse | |
| (no geometric meaning) | depends on where the origin is |
"" gives different answers if you move the origin, so geometric code avoids it, with one useful exception: weighted averages such as the midpoint , whose weights add up to 1, are independent of the origin.
from sympy import Matrix, Rational
P = Matrix([2, 6])
Q = Matrix([8, 0])
mid = Rational(1, 2) * P + Rational(1, 2) * Q
print("midpoint:", list(mid))
print("one third of the way:", list(P + Rational(1, 3) * (Q - P)))
# shift the origin by (100, 100): the midpoint moves with it, P + Q does not
shift = Matrix([100, 100])
print(list(Rational(1, 2) * (P + shift) + Rational(1, 2) * (Q + shift) - shift))
print(list((P + shift) + (Q + shift) - shift), "vs", list(P + Q))midpoint: [5, 3]
one third of the way: [4, 4]
[5, 3]
[110, 106] vs [10, 6]
In software
- Graphics and games keep points and directions apart with homogeneous coordinates: a point is and a direction is . A translation matrix then moves points but leaves directions (velocities, normals) unchanged. See Game Math: Homogeneous Coordinates and Game Math: Vectors.
- Typed math libraries (for example separate
Point3andVector3types in some engines and in Rust crates likenalgebra) make "" a compile error. - Machine learning calls a row of a dataset a feature vector; distances between such points drive k-nearest neighbours and clustering (k-means).
The calculus courses meet vectors too: Vectors in Calculus and the deeper Vectors lesson.
Exercises
Exercise 1: Displacement
Find the vector from to , and from to .
Answer
, .
Solution
Exercise 2: Find the missing point
The vector from to is and . What is ?
Answer
.
Solution
Exercise 3: Parallelogram
Three corners of a parallelogram are , and , with and as sides. Find the fourth corner .
Answer
.
Solution
is reached from by the same vector that takes to .
Exercise 4: Points along a segment (code)
Write along(P, Q, t) that returns , and print the points for with , .
Answer
, , , , .
Solution
This is linear interpolation (lerp), see Game Math: Lerp.
import numpy as np
def along(P, Q, t):
return P + t * (Q - P)
P, Q = np.array([0, 0, 0]), np.array([8, 4, -4])
for t in [0, 0.25, 0.5, 0.75, 1]:
print(t, along(P, Q, t))0 [0 0 0]
0.25 [ 2. 1. -1.]
0.5 [ 4. 2. -2.]
0.75 [ 6. 3. -3.]
1 [ 8 4 -4]
Test yourself
What is the result of subtracting one point from another?
- A point
- A vector
- A number
- It is undefined
Are the arrow from to and the arrow from to the same vector?
- Yes, both are
- No, they start at different points
- Only if the origin is moved
- No, they have different lengths
In homogeneous coordinates, how is a direction vector distinguished from a point?
- It has
- It has negative components
- It has , so translations do not affect it
- It is normalized