Dot Product Calculator
Result
Dot product
- Magnitude of u
- 3.0000
- Magnitude of v
- 3.0000
- Angle between vectors
- 27.2660 °
A dot product calculator takes two vectors and returns their dot product — also known as the inner product — the length of each of them, and the angle between them. Type the components of each vector separated by spaces or commas — 1 2 2 for a three-dimensional vector, 0 3 for a two-dimensional one — and the page does the rest. A vector is a list of numbers that stands for something with both a size and a direction: a wind of 30 kilometres an hour from the north-east, a force pushing down and sideways, the direction a camera is pointing. The dot product of two of them is worked out by multiplying the two first components, the two second components, the two third components, and adding up all the products. That single number turns out to say something about how the two vectors point relative to each other, which is why it turns up everywhere from lighting calculations in games to the definition of work in physics. Its value is largest when the two point the same way, zero when they are at right angles, and negative when they point in opposite directions. The page converts that into the angle directly, using the fact that the dot product equals the two lengths multiplied together and then multiplied by the cosine of the angle between them. Rearranged, the cosine is the dot product divided by the product of the two lengths, and the angle is the inverse cosine of that. Three answers are worth recognising on sight. A dot product of zero means the vectors are perpendicular, because the cosine of 90 degrees is zero, and that is the single most useful thing this page does — testing whether two directions are at right angles without measuring anything. Equal vectors give angle zero, since they point the same way. Opposite vectors give 180 degrees. One input is refused rather than answered: the zero vector, which has no direction at all. Its dot product with anything is zero, and dividing by its length to get an angle would mean dividing by zero, so the page declines the whole calculation rather than returning a partial answer with a gap in it. Everything else is accepted, including vectors of any length as long as the two match, and negative components, which are how a vector pointing left or down is written.
Vector pairs and what they come to
| Vector u | Vector v | Dot product | |u| | |v| | Angle (°) |
|---|---|---|---|---|---|
| 1 2 2 | 2 2 1 | 8 | 3 | 3 | 27.266 |
| 3 4 0 | 4 3 0 | 24 | 5 | 5 | 16.2602 |
| 1 0 | 0 1 | 0 | 1 | 1 | 90 |
| 1 1 1 | 1 1 1 | 3 | 1.7321 | 1.7321 | 0 |
| 1 2 3 | 4 5 6 | 32 | 3.7417 | 8.775 | 12.9332 |
| -1 0 0 | 1 0 0 | -1 | 1 | 1 | 180 |
| 2 -3 | 4 5 | -7 | 3.6056 | 6.4031 | 107.6501 |
| 1 2 | 3 4 | 11 | 2.2361 | 5 | 10.3048 |
Eight pairs, and the first row is the one the page loads with. The second column is the place to look for the three answers worth recognising on sight. The third row is the plainest right angle there is, one vector along each axis, and its dot product is zero with the angle coming back as exactly 90 — that is the perpendicularity test the page is most often used for, and it needs none of the trigonometry the angle column uses. The fourth row is two copies of the same vector, giving the largest dot product on the table and an angle of 0, and the sixth is a vector and its own negation, giving the only negative dot product here and an angle of 180. Between them those three rows are the whole range: same direction, right angle, opposite direction. The fifth row is the untidy pair whose lengths are both square roots, and it is the row that shows the angle is computed from the unrounded magnitudes — multiplying 3.7417 by 8.775 and dividing 32 by the result gets the same 12.9332, but only just. The seventh row carries negative and mixed-sign components, which is how a vector pointing left or down is written, and its dot product of −7 with an angle of 107.6501 is the case where the sign and the angle have to agree: above 90 degrees and negative, as they should be. The eighth row is a two-dimensional pair, since the page takes any number of components. Every figure here is recomputed when the page is built, and the dots in the first two columns are the separators, not part of the numbers.
Formula
u · v = u₁v₁ + u₂v₂ + … + uₙvₙ |u| = √(u₁² + u₂² + … ) cos θ = (u · v) ÷ (|u| × |v|)
- Vector u
- The first vector, written as its components separated by spaces or commas: 1 2 2 for three dimensions, 0 3 for two, or as many as you need. There is no fixed number of boxes because the page accepts any dimension, and the two vectors must have the same number of components
- Vector v
- The second vector, written the same way and with the same number of components as the first. Order does not matter for the dot product or the angle — swapping the two vectors gives the same answers
- u · v
- The dot product: multiply the two first components together, the two second components, and so on, and add up the results. It is a single plain number with no unit attached, since a vector's components carry whatever unit the quantity has and the product of two of them would carry that unit squared
- |u| and |v|
- The magnitude of each vector, in whatever unit the components were measured in: the square root of the sum of the squares of its components. This is the ordinary length of the arrow, and it is the same calculation as the distance from the origin to the point the vector points at
- θ
- The angle between the two vectors, in degrees, from 0 when they point the same way through 90 when they are perpendicular to 180 when they point in opposite directions. It never leaves that range, because the inverse cosine cannot return anything outside it
- cos θ
- The dot product divided by the product of the two magnitudes, which is the bridge between the two halves of this page. It runs from 1 for vectors pointing the same way through 0 at a right angle to −1 for vectors pointing in opposite directions, and it is the number the angle is actually computed from
- Degrees
- The unit of the angle output, and the only output on the page that has a unit at all. The dot product and the two magnitudes are plain numbers
- Four decimal places
- How wide every output is written. The dot product is often a whole number when the components are; the two magnitudes carry a square root and the angle carries an inverse cosine, so those three almost never come out exact
The dot product is the standard way to ask how much two directions agree, and the questions it answers come up more often than the arithmetic suggests. Perpendicularity is the big one: if the dot product is zero the two vectors meet at a right angle, which is how a program decides whether a surface faces a light, whether a path crosses a wall, or whether two lines in a drawing are square to each other — and it takes only the multiplications, with no trigonometry anywhere. The sign is the next thing to look at: positive means the two point broadly the same way, negative means broadly opposite, and that is the whole of the test behind backface culling and behind whether a force is doing work on an object or against it. Physics uses the same number under the name of work: the work done by a force is the force dot the distance moved, which is why pushing at an angle does less than pushing straight on, and why pushing at a right angle does none at all. When you do want the angle itself rather than just the relationship, the page gives it, and the figures to recognise are 0, 90 and 180 degrees — parallel, perpendicular and opposed. Anything else is a vector pair that has drifted off those three, and the useful check is that the dot product's sign should match the angle: a negative dot product and an angle under 90 degrees cannot both be right.
Worked examples
1 2 2 and 2 2 1
- Dot product: 1 × 2 + 2 × 2 + 2 × 1 = 2 + 4 + 2 = 8
- Length of u: √(1 + 4 + 4) = √9 = 3
- Length of v: √(4 + 4 + 1) = √9 = 3
- Cosine: 8 ÷ (3 × 3) = 0.888889, and the inverse cosine of that is 27.2659…, which rounds to 27.266
The input the page loads with, and a tidy one: both vectors have length exactly 3, so the cosine is simply the dot product divided by nine. Two different vectors, one dot product, two magnitudes, one angle — the whole page in one row. The angle is under 90 degrees and the dot product is positive, which is the sign check worth running on every answer.
3 4 0 and 4 3 0
- Dot product: 3 × 4 + 4 × 3 + 0 × 0 = 12 + 12 = 24
- Length of each: √(9 + 16) = 5, since the third component is zero
- Cosine: 24 ÷ (5 × 5) = 0.96, and the inverse cosine of that is 16.2602…
Two vectors lying in the flat plane, written with an explicit zero for the third component to show that a two-dimensional vector is just a three-dimensional one with a zero in it. Both lengths come out exactly 5, which is the 3-4-5 triangle doing its usual work. The angle is small and the dot product is large and positive, which is the shape of two vectors pointing much the same way.
1 0 and 0 1
- Dot product: 1 × 0 + 0 × 1 = 0
- Length of each: 1
- Cosine: 0 ÷ 1 = 0, and the inverse cosine of zero is exactly 90 degrees
The answer the page is most often used for. A dot product of zero means the two vectors are perpendicular, and these two are the plainest possible example: one along the x-axis, one along the y-axis. Notice that the angle comes back as exactly 90 rather than a rounded figure, because the cosine is exactly zero and no square root or division was needed to get there. This is the test for a right angle, and it needs none of the trigonometry the angle output uses.
1 2 3 and 4 5 6
- Dot product: 1 × 4 + 2 × 5 + 3 × 6 = 4 + 10 + 18 = 32
- Length of u: √(1 + 4 + 9) = √14 = 3.741657…, which rounds to 3.7417
- Length of v: √(16 + 25 + 36) = √77 = 8.774964…, which rounds to 8.775
- Cosine: 32 ÷ (3.741657 × 8.774964) = 0.974631…, and the inverse cosine of that is 12.9331…, which rounds to 12.9332
Two vectors with no tidy lengths, and the row to look at if you want to see what the rounding costs. Both magnitudes are square roots that never end, so the cosine is computed from their unrounded values rather than from the 3.7417 and 8.775 on screen, which is why dividing 32 by the product of the two printed figures gives 0.9746 and lands on the same angle but only just. The angle is small because the two vectors are close to parallel — 4 5 6 is roughly 1 2 3 scaled up.
-1 0 0 and 1 0 0
- Dot product: (−1) × 1 + 0 × 0 + 0 × 0 = −1
- Length of each: 1
- Cosine: −1 ÷ 1 = −1, and the inverse cosine of −1 is exactly 180 degrees
The other end of the range. Two vectors pointing in exactly opposite directions have a dot product equal to minus the product of their lengths, and here that is −1, which gives a cosine of −1 and an angle of 180 degrees. This is the row that shows why the dot product can be negative and what a negative value means: not an error and not a smaller angle, but two arrows pointing away from each other.
Limitations
The two vectors must have the same number of components, and the page refuses a pair that does not rather than padding the shorter one with zeros. The zero vector is refused entirely: a vector with every component zero has no direction, so the angle between it and anything else is undefined, and the page declines the whole calculation rather than showing an angle of zero that would read as pointing the same way. Components are read as ordinary numbers: a comma followed by a space separates components, a comma with no space after it is read as a decimal point (1,5 is one and a half), and a thousands grouping is refused rather than guessed at — write 1500, not 1,500. Up to 200 components are accepted in each vector, which is far beyond any hand-written case and short of the sizes a data pipeline would use. Four decimal places is a display width rather than a claim about precision, and the angle is computed from the unrounded magnitudes, so multiplying the printed figures together may not reproduce the printed angle exactly. The page is for the dot product and the angle only: it does not give the cross product, the projection of one vector onto the other, or the unit vectors, and it takes no account of what the components are measured in, so a dot product computed from components in metres comes back as a plain number rather than in square metres.
Frequently asked questions
- How do I type the components?
- Separate them with spaces or with a comma and a space: 1 2 2 and 1, 2, 2 both work. A comma sitting between two digits with no space after it is read as a decimal point (1,5 is one and a half); a thousands grouping such as 1,500 is refused rather than guessed at, so write 1500. The two vectors must have the same number of components, and there is no limit on how many as long as they match — two dimensions and three dimensions are the same page.
- What does the dot product actually tell me?
- How much the two vectors point the same way. It is largest when they are parallel and pointing the same way, zero when they are perpendicular, and negative when they point in opposite directions. Its value also depends on how long the vectors are, so a big dot product on long vectors does not mean a small angle — divide by the two lengths, which the page does for you, and you get the cosine of the angle.
- How do I tell whether two vectors are perpendicular?
- Their dot product is zero. That is the whole test, and it takes only the multiplications — no square roots and no trigonometry, which is why it is the form used in code. The page still gives you the angle, and it will read 90, but if perpendicularity is all you need, the dot product alone settles it.
- Why can the dot product be negative?
- Because it tracks direction as well as size. Two vectors pointing broadly toward each other give a positive number; at right angles the two contributions cancel and the product is zero; pointing broadly away from each other gives a negative one. A negative dot product always goes with an angle above 90 degrees, and the two should never disagree — if they do, something is wrong with the inputs.
- Why does it refuse a vector of all zeros?
- Because the zero vector has no direction, so the angle between it and anything else is undefined. Its dot product with anything is zero and its length is zero, so working out the cosine would mean dividing by zero. A page that returned 0 degrees would be saying it points the same way as your vector, which is a statement about a direction that does not exist.
- What units is the answer in?
- The angle is in degrees and the other three outputs have no unit at all. The dot product is a sum of products of components, so if the components were measured in metres it is in square metres, and if they were plain numbers it is a plain number; the page leaves the unit off rather than guessing, since the same arithmetic serves a direction, a force and a list of test scores.
References
- Dot product — the sum of the products of corresponding components, with the geometric interpretation as the product of the two lengths and the cosine of the angle between them that this page inverts — Wolfram MathWorld (United States)
- Vector — the object with a magnitude and a direction whose components this page reads, and whose length is the square root of the sum of the squares of those components — Wolfram MathWorld (United States)
- Perpendicular — the right-angle relation that a dot product of zero detects, which is the commonest use of this calculation and needs none of its trigonometry — Wolfram MathWorld (United States)
- 教育部关于印发义务教育课程方案和课程标准(2022 年版)的通知——The fifth item in the annex list of this notice is the Mathematics Curriculum Standards for Compulsory Education (2022 edition); plane vectors and their scalar (dot) product are part of the upper-secondary mathematics curriculum, and the wording of the standards and the grade-band breakdown are governed by that annex — 中华人民共和国教育部