The idea: a vector is an arrow you can compute with

A 2D vector is a pair of numbers a = (a₁, a₂). Draw it as an arrow from the origin to the point (a₁, a₂): it has a length |a| = √(a₁² + a₂²) and a direction. Where the arrow starts does not matter; sliding it without turning it gives the same vector. The page keeps two vectors a and b on a grid and builds each operation from them, step by step, with the arithmetic in the Numbers panel.

Left: a = (3, 1) and b = (1, 2) from the origin, a copy of b placed at the tip of a, and a + b = (4, 3) from the origin to the tip of the copy. Right: a = (3, 1), 2a = (6, 2) along the same line, and minus a = (minus 3, minus 1) pointing the other way
Addition puts b's tail on a's tip; scaling by k stretches the arrow along its own line, and k < 0 flips it.

Addition and scaling

Addition works component by component: a + b = (a₁ + b₁, a₂ + b₂). Geometrically it is tip to tail: slide a copy of b so that its tail sits on the tip of a; the sum runs from the origin to the tip of that copy. With a = (3, 1) and b = (1, 2) the sum is (4, 3), length 5, which is less than |a| + |b| ≈ 5.40: the triangle inequality (Demo: add vectors tip to tail).

Scaling by a number k multiplies both components: 2·(3, 1) = (6, 2). The arrow stays on the same line and its length is multiplied by |k|; a negative k also reverses it. Pick 2·a, −1·a or ½·a in the operation list.

The dot product: two formulas, one number

The dot product of two vectors is a single number, and it has two formulas that always agree:

a·b=a1b1+a2b2=|a||b|cosθ

The first is arithmetic: multiply matching components and add (in n dimensions, Σ aᵢbᵢ). The second is geometry: θ is the angle between the arrows. For a = (3, 1), b = (1, 2): 3·1 + 1·2 = 5, and √10 × √5 × cos 45° = 7.07 × 0.707 = 5 (Demo: dot product, acute pair). The agreement is the law of cosines in disguise, and it is how you find an angle from coordinates: cos θ = a·b / (|a||b|).

The sign tells the angle

Lengths are never negative, so the sign of a·b is the sign of cos θ:

Three small planes with a = (3, 1). Acute: b = (1, 2), a dot b = 5, theta = 45 degrees, cos theta greater than 0. Perpendicular: b = (minus 1, 3), a dot b = 0, theta = 90 degrees with a right-angle mark. Obtuse: b = (minus 3, 1), a dot b = minus 8, theta about 143.13 degrees, cos theta less than 0
Same a, three b's: the dot product is positive, zero or negative as the angle is acute, right or obtuse.
a·bangle θmeaningdemo
> 0acute, θ < 90°point roughly the same way(3, 1)·(1, 2) = 5
= 0θ = 90°perpendicular (orthogonal)(3, 1)·(−1, 3) = 0
< 0obtuse, θ > 90°point apart(3, 1)·(−3, 1) = −8

A zero dot product is the standard test for perpendicular vectors (Demo: perpendicular pair); a negative one means more than a right angle apart, here θ ≈ 143.13° (Demo: obtuse pair).

Cosine similarity

Dividing by the lengths leaves only the direction: cos θ = a·b / (|a||b|), between −1 and 1. This is cosine similarity, the score search engines and retrieval-augmented generation (RAG) use to find the text chunks whose embedding vectors point the same way as the question's. The page shows it as the last line of every dot product.

Projection of a onto b

The projection of a onto b is a's shadow on the line through b: drop a perpendicular from a's tip to that line.

projba=a·bb·bb

Its signed length is a·b / |b| = |a| cos θ, which is another way to read the dot product: the length of a's shadow times the length of b. For a = (1, 3), b = (3, 1): a·b = 6, b·b = 10, so the projection is 0.6·(3, 1) = (1.8, 0.6), length 1.90. What is left over, a − proj = (−0.8, 2.4), is perpendicular to b: its dot product with b is 0 (Demo: projection of a onto b). When a·b < 0 the projection points against b.

The 2D cross product is a signed area

In 2D the cross product is the number a × b = a₁b₂ − a₂b₁ (the z part of the 3D cross product, and the determinant of the 2×2 matrix with columns a and b). Its size is the area of the parallelogram with sides a and b, |a||b| sin θ. Its sign is the turn: positive when b is counter-clockwise from a, negative when clockwise, zero when they are parallel. For (3, 1) and (1, 2): 3·2 − 1·1 = 5 squares, and b × a = −5 (Demo: cross product = area).

Left: a = (1, 3) and b = (3, 1), a dashed line through b, a dashed perpendicular from the tip of a, and the projection (1.8, 0.6) on b. Right: a = (3, 1), b = (1, 2) and dashed copies closing a hatched parallelogram labelled area = 5
The projection is a's shadow on b's line; a₁b₂ − a₂b₁ is the area of the parallelogram, + because b is counter-clockwise from a.

Geometry code uses the sign constantly: which side of a line a point is on, whether a polygon turns left or right (convex hull), and whether two segments cross. Rotations and scalings of the whole plane are covered in 2D rotation and scaling, and the area-scaling factor of a matrix is its determinant.

Projecting onto a plane instead of a line gives least squares, the best fit for a system with no solution. The length |v| = √(x² + y²) is the Pythagorean theorem; see the Pythagorean theorem, including the law of cosines behind a·b = |a||b|cos θ.

Ray tracers use the dot product N·L for shading and R = D − 2(D·N)N for mirrors: see Ray Tracing.

See also Word2Vec: training word vectors by pushing dot products up for neighbours and down for random words, and cosine-based analogies.

What the page leaves out

Only 2D integer vectors are drawn. The dot product works the same in any dimension (Σ aᵢbᵢ), but the cross product as a vector exists only in 3D (and 7D). Unit vectors and normalization, bases and coordinates, the vector triple product, complex inner products and the proof of the law of cosines are not shown. See also complex numbers, where multiplying by i turns a vector by 90°, and eigenvectors.