TExcelTAD
Home › Linear Algebra & Matrix Theory › Points and Vectors

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 Rn\mathbb{R}^n both are written as lists of nn numbers, and the difference between them matters a lot in geometry and in graphics code.

Rn\mathbb{R}^n: lists of nn numbers

Rn\mathbb{R}^n is the set of all ordered nn-tuples of real numbers (x1,x2,…,xn)(x_1, x_2, \ldots, x_n). For n=2n = 2 it is the plane, for n=3n = 3 ordinary space, and for larger nn it is just as useful even if we cannot draw it: a colour is a point in R3\mathbb{R}^3 (red, green, blue), a 28×2828 \times 28 grey-scale image is a point in R784\mathbb{R}^{784}, and an LLM token embedding is a point in R768\mathbb{R}^{768} or more.

In linear algebra a vector is usually written as a column:

v=[3−12]=(3,−1,2)(the round-bracket form saves space on a page)\mathbf{v} = \begin{bmatrix} 3 \\ -1 \\ 2 \end{bmatrix} = (3, -1, 2) \qquad \text{(the round-bracket form saves space on a page)}

The numbers are the components (or entries, or coordinates) of v\mathbf{v}. Two vectors are equal when they have the same number of components and every component agrees.

From two points to a vector

Given points P=(p1,…,pn)P = (p_1, \ldots, p_n) and Q=(q1,…,qn)Q = (q_1, \ldots, q_n), the vector from PP to QQ is

PQ→=Q−P=(q1−p1,q2−p2,…,qn−pn)\overrightarrow{PQ} = Q - P = (q_1 - p_1, q_2 - p_2, \ldots, q_n - p_n)

It tells you how far to move in each coordinate direction to walk from PP to QQ. Vectors have no fixed position: the arrow from (0,0)(0, 0) to (2,1)(2, 1) and the arrow from (5,3)(5, 3) to (7,4)(7, 4) are the same vector (2,1)(2, 1), drawn at two places.

text
y
4 |                  · Q'(7,4)
3 |              ·──┘ P'(5,3)        both arrows are the vector (2, 1)
2 |
1 |      · Q(2,1)
0 · P ──┘
  └──────────────────────── x

The vector from the origin OO to a point PP is the position vector of PP; its components are the coordinates of PP. That is why the same list of numbers can describe either, and why it is easy to mix them up.

python · try it yourself
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
point−point\text{point} - \text{point} vector displacement between them
point+vector\text{point} + \text{vector} point move the point
vector+vector\text{vector} + \text{vector} vector combine displacements
number⋅vector\text{number} \cdot \text{vector} vector stretch or reverse
point+point\text{point} + \text{point} (no geometric meaning) depends on where the origin is

"Point+point\text{Point} + \text{point}" gives different answers if you move the origin, so geometric code avoids it, with one useful exception: weighted averages such as the midpoint 12P+12Q\frac{1}{2}P + \frac{1}{2}Q, whose weights add up to 1, are independent of the origin.

python · try it yourself
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 (x,y,z,1)(x, y, z, 1) and a direction is (x,y,z,0)(x, y, z, 0). 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 Point3 and Vector3 types in some engines and in Rust crates like nalgebra) make "point+point\text{point} + \text{point}" 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 P=(3,−2)P = (3, -2) to Q=(−1,4)Q = (-1, 4), and from QQ to PP.

Answer

PQ→=(−4,6)\overrightarrow{PQ} = (-4, 6), QP→=(4,−6)\overrightarrow{QP} = (4, -6).

Solution
Q−P=(−1−3,4−(−2))=(−4,6)P−Q=−(Q−P)=(4,−6)\begin{aligned} Q - P &= (-1 - 3, 4 - (-2)) = (-4, 6) \\ P - Q &= -(Q - P) = (4, -6) \end{aligned}

Exercise 2: Find the missing point

The vector from AA to BB is (2,5,−1)(2, 5, -1) and B=(0,1,1)B = (0, 1, 1). What is AA?

Answer

A=(−2,−4,2)A = (-2, -4, 2).

Solution
B−A=(2,5,−1)→A=B−(2,5,−1)=(0−2,1−5,1+1)=(−2,−4,2)B - A = (2, 5, -1) \to A = B - (2, 5, -1) = (0 - 2, 1 - 5, 1 + 1) = (-2, -4, 2)

Exercise 3: Parallelogram

Three corners of a parallelogram are A=(1,1)A = (1, 1), B=(4,2)B = (4, 2) and D=(2,4)D = (2, 4), with ABAB and ADAD as sides. Find the fourth corner CC.

Answer

C=(5,5)C = (5, 5).

Solution

CC is reached from DD by the same vector that takes AA to BB.

AB→=B−A=(3,1)C=D+AB→=(2+3,4+1)=(5,5)Check: C−B=(1,3)=D−A✓\begin{aligned} \overrightarrow{AB} &= B - A = (3, 1) \\ C &= D + \overrightarrow{AB} = (2 + 3, 4 + 1) = (5, 5) \\ &\text{Check: } C - B = (1, 3) = D - A \checkmark \end{aligned}

Exercise 4: Points along a segment (code)

Write along(P, Q, t) that returns P+t⋅(Q−P)P + t \cdot (Q - P), and print the points for t=0,0.25,0.5,0.75,1t = 0, 0.25, 0.5, 0.75, 1 with P=(0,0,0)P = (0, 0, 0), Q=(8,4,−4)Q = (8, 4, -4).

Answer

(0,0,0)(0, 0, 0), (2,1,−1)(2, 1, -1), (4,2,−2)(4, 2, -2), (6,3,−3)(6, 3, -3), (8,4,−4)(8, 4, -4).

Solution

This is linear interpolation (lerp), see Game Math: Lerp.

python · try it yourself
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?

  1. A point
  2. A vector
  3. A number
  4. It is undefined

Are the arrow from (0,0)(0, 0) to (3,1)(3, 1) and the arrow from (2,2)(2, 2) to (5,3)(5, 3) the same vector?

  1. Yes, both are (3,1)(3, 1)
  2. No, they start at different points
  3. Only if the origin is moved
  4. No, they have different lengths

In homogeneous coordinates, how is a direction vector distinguished from a point?

  1. It has w=1w = 1
  2. It has negative components
  3. It has w=0w = 0, so translations do not affect it
  4. It is normalized