Direction often matters more than size. The cosine similarity calculator takes the components of two vectors and gives the cosine similarity, the angle between them, the cosine distance, the dot product and the length of each vector.
How the calculation works
- Enter the three components of vector A and of vector B. For vectors with two components, set the third to 0.
- The cosine similarity is A · B ÷ (|A| × |B|), the dot product divided by the product of the lengths.
- It runs from −1, vectors pointing in opposite directions, through 0, perpendicular vectors, to +1, vectors pointing the same way.
- The angle is the inverse cosine of the similarity, and the cosine distance is 1 minus the similarity.
Example
Take A = (2, 5, 1) and B = (4, 3, 6). The dot product is 8 + 15 + 6 = 29. The lengths are √30 = 5.4772 and √61 = 7.8102. The cosine similarity is 29 ÷ 42.778 = 0.6779, which corresponds to an angle of 47.3°.
Why it matters
Cosine similarity is a core tool in information retrieval, machine learning and data science, and also a basic geometric idea in physics and engineering. A calculator helps check hand computations and build intuition, for instance by showing how rescaling a vector leaves the similarity unchanged while the dot product grows.
Good to know
The calculator handles three components. For longer vectors such as word-count tables, the idea is the same but the sums include every component. A zero vector has no direction, so the similarity is reported as 0 in that case. The angle is given in degrees between 0 and 180.
Related tools
The vector calculator covers other operations on vectors, and the trigonometry calculator helps with the angle.