Lesson
The theory — Vector Calculator
The dot product of two vectors can be written two ways that look nothing alike: multiply matching components and add, or multiply the two lengths by the cosine of the angle between them. They always agree, and that agreement is what makes the dot product useful — it converts geometry into arithmetic.
What each symbol means
A · B- the dot product: one number, not a vector. At the defaults
2·−1 + 1·2 = 0. |A|- the length (magnitude) of a vector, from Pythagoras:
√(2² + 1²) = 2.2361. θ- the angle between the two vectors, which the page reports in radians and degrees at once —
1.5708 rad = 90°for the defaults. comp- the scalar projection — how much of one vector lies along the other. It is the dot product divided by the length of the vector you are projecting onto.
Where the formula comes from
- Take the triangle formed by
A,Band the vectorA − Bjoining their tips. The law of cosines relates its sides:|A − B|² = |A|² + |B|² − 2|A||B|cos θ. - Now expand the same
|A − B|²componentwise instead. Every squared term reassembles into|A|²and|B|², and what is left over is−2(AxBx + AyBy). - Set the two expressions equal and the
|A|²and|B|²cancel, leavingAxBx + AyBy = |A||B|cos θ. Rearranged, that is exactly the angle formula on the page:θ = arccos(A·B / (|A||B|)).
How to read what you see
Each line shows the substitution, not just the answer: the dot product as A·B = AxBx + AyBy = 2·−1 + 1·2 = 0, both lengths from Pythagoras, then the angle as arccos(0) = 1.5708 rad = 90°. Leave both z boxes at 0 and the vectors are printed as two-component columns; give either one a z and the display becomes three-dimensional.
- Assumes
- Cartesian coordinates with perpendicular axes and the same unit on each. The formulas above are for that case; on a map projection, or in any coordinate system whose axes are not at right angles, the componentwise recipe is no longer the dot product.
- Breaks when
- A dot product of exactly
0means perpendicular — but it means that for any pair of perpendicular vectors, however long, so it tells you nothing about size. And the angle it recovers is always the unsigned one between 0 and 180°: swappingAandBgives the identical answer, so the dot product alone can never tell you which way you turned.
Problems solved in full
-
The spanned area for A = (2, 1) and B = (−1, 2) 6 steps
A = (2, 1) and B = (−1, 2). The dot product is zero and the spanned area is 5. Show that both facts are the same fact.
-
Two vectors, and the dot product is the sum of the coordinatewise products. It comes out to zero, which already answers the geometry.
-
Both lengths are the same, and they are the same for a reason that will surface in step 5.
-
Cosine of the angle is the dot product over the product of lengths. Zero over anything is zero, and the arccosine of zero is a right angle.
-
The spanned area is the determinant, which for perpendicular vectors is simply the product of the lengths — √5 × √5.
-
Here is why the lengths matched. A quarter-turn rotation swaps the coordinates and flips one sign, and applying it to A produces B exactly.
-
The projection confirms it from the other side: nothing of A lies along B, so subtracting the projection leaves A untouched.
Answer
Because B is A rotated by a quarter turn. The rotation (x, y) → (−y, x) sends (2, 1) to exactly (−1, 2), which forces the angle to be 90° and therefore the dot product to be zero. It also preserves length, so both vectors are √5, and the parallelogram they span is a square of side √5 — area 5, which is what the panel prints. The dot and cross products are the two halves of one product: |A||B| cos θ and |A||B| sin θ. At 90° the first is empty and the second is everything, and the projection of A onto B is the zero vector, meaning A has no component along B at all. Turn either vector a few degrees and both numbers move, always keeping their squares summing to |A|²|B|² = 25.
-
-
Dot product of 32 and cross-product magnitude of 7.3485 6 steps
A = (1, 2, 3), B = (4, 5, 6). The panel prints a dot product of 32 and a cross-product magnitude of 7.3485. Show that those two numbers are not independent. This is the 3D angle state.
-
Dot product and both lengths, straight from the definitions. Neither square root is nice, which is the usual state of affairs in three dimensions.
-
The angle follows. At 12.9° these two vectors are nearly parallel, which is worth noticing before the next step: the cross product is going to be small.
-
The cross product is the determinant of a 3×3 with the unit vectors on the top row. Its magnitude is the area of the parallelogram.
-
Now put the two products together. Square each, add, and compare with the product of the squared lengths.
-
Divide the identity through by |A|²|B|² and the trigonometry appears — the same identity, in the coordinates you started with.
-
One more line confirms the cross product is doing what it claims: it is orthogonal to A, and by symmetry to B.
Answer
32² + 7.3485² = 1078 = 14 × 77 = |A|²|B|². That is Lagrange's identity, and it is the Pythagorean identity in disguise: divide through by |A|²|B|² and it reads cos²θ + sin²θ = 1. So the dot and cross products are not two separate measurements of two separate things — they are the adjacent and opposite sides of the same right triangle, and knowing one plus the two lengths determines the other up to sign. The practical consequence is that you should never compute an angle from the dot product alone when it is near zero or near 180°: the cosine is flat there, and the cross product, whose sine is steep, is the numerically better route.
-
Learning path
Fitting a line to data
References (1)
- The dot product from both directions, and why the two definitions agree: G. Strang, Introduction to Linear Algebra, 5th ed. Wellesley-Cambridge Press, 2016. ISBN 978-0-9802327-7-6.