A vector calculator works with vectors of two or more components: it finds the dot product, the cross product, the angle between two vectors, the cosine similarity, the magnitude, the unit vector, direction angles, sums and differences, scalar multiples and projections. Type the components, choose the operation and press the button. The formulas follow the Wikipedia pages on the dot product, the cross product, cosine similarity and Euclidean vectors, and the work is done in your browser.
How to use the vector calculator
- Choose what you want: for example the dot product or the angle.
- Type vector A with its components separated by commas or spaces, such as 1, 2, 3.
- Type vector B in the same way, when the operation uses two vectors. Both vectors must have the same number of components.
- For a multiple, type the number to multiply by.
- Press Work out the result.
The dot product
The Wikipedia page on the dot product defines it as the sum of the products of the matching components [1]. It also equals the length of A times the length of B times the cosine of the angle between them. For (1, 2, 3) and (4, −5, 6) the sum is 4 minus 10 plus 18, which is 12. The result is a single number, not a vector. It is zero when the vectors are perpendicular, positive when the angle between them is less than 90 degrees and negative when it is more.
The cross product
In three dimensions the cross product of A and B is a vector perpendicular to both. The page gives its components as a2 b3 minus a3 b2, then a3 b1 minus a1 b3, then a1 b2 minus a2 b1 [2]. For (1, 2, 3) and (4, 5, 6) that gives (−3, 6, −3). Its length is the length of A times the length of B times the sine of the angle between them, which is the area of the parallelogram that the two vectors span. The direction follows the right-hand rule, so B cross A is the negative of A cross B. The calculator shows the vector and its magnitude.
The angle between two vectors
Rearranging the dot product formula gives the angle as the inverse cosine of the dot product divided by the product of the two lengths. For (1, 0) and (0, 1) the dot product is 0, so the angle is 90 degrees. For two vectors that point the same way, the angle is 0, and for opposite vectors it is 180. The calculator works out the angle in a way that stays accurate for nearly parallel vectors, and shows it in degrees and radians together with the cosine.
Cosine similarity
The Wikipedia page on cosine similarity defines it as the dot product divided by the product of the lengths, which is the cosine of the angle between the vectors [3]. It runs from −1 to 1. It is used in search and in machine learning to compare documents or items, because it ignores how long the vectors are and looks only at their direction. For (1, 2, 3) and (4, −5, 6) it is 12 divided by the square root of 1,078, about 0.3655.
Magnitude, unit vector, sums, multiples and projections
The magnitude is the square root of the sum of the squares of the components, as on the page about Euclidean vectors [4]. For (3, 4) it is 5, and dividing each component by 5 gives the unit vector (0.6, 0.8). Adding or subtracting vectors works on matching components, and multiplying by a number scales each component. The projection of A onto B is the dot product of A and B divided by the squared length of B, times B. For (3, 4) onto (1, 0) it is (3, 0), and the scalar projection is 3.
When vectors are useful
Vectors describe forces, velocities, directions and positions in physics and engineering, and the dot and cross products turn up in work, torque and area calculations. In computer graphics they give the lighting on a surface, and in data science they stand for items with many features. The calculator works with up to 8 components, so it handles both the three dimensions of physics and small feature vectors.
A worked example with the angle
Take A = (2, 0, 0) and B = (1, 1, 0). The dot product is 2, the magnitude of A is 2 and the magnitude of B is the square root of 2, so the cosine of the angle is 2 divided by 2 times the square root of 2, which is about 0.7071. The angle is 45 degrees. The cross product is (0, 0, 2), a vector pointing straight up from the flat plane that holds both vectors, and its length of 2 equals the area of the parallelogram they span. You can check each of these numbers in the calculator by choosing the operation and entering the two vectors.
Direction angles and direction cosines
The direction cosines of a vector are the cosines of the angles it makes with the three positive coordinate axes. They are the components divided by the magnitude, so their squares add to 1, and they are the coordinates of the unit vector [5]. For (1, 2, 2), whose magnitude is 3, the direction cosines are 1/3, 2/3 and 2/3, and the angles are 70.5288°, 48.1897° and 48.1897°, as the calculator works out. For a vector with two components it also gives the angle from the positive x axis, from 0° to 360°, which is our own arctangent working: (−1, 0) gives 180°. The calculator accepts up to eight components for the other operations, and only the cross product is limited to three.
Common mistakes
- Using the cross product in two dimensions. It needs exactly three components.
- Mixing up the dot and cross products. One is a number, the other a vector.
- Expecting the order not to matter for the cross product. Swapping the vectors reverses the sign.
- Using a zero vector for an angle. It has no direction.
- Giving vectors of different sizes. The two must have the same number of components.
What next
- Pythagorean Theorem Calculator
- Distance Between Two Points Calculator
- 3 Sides Triangle Area Calculator
Use this often? Add Vector to your Home screen.
Frequently asked questions
What is a vector calculator?
A tool that does arithmetic with vectors: dot and cross products, angles, magnitude, unit vectors, sums, multiples and projections.
How do you find the dot product of two vectors?
Multiply the matching components and add the results. (1, 2, 3) · (4, −5, 6) = 4 − 10 + 18 = 12.
How do you find the cross product?
For 3D vectors, use (a2b3 − a3b2, a3b1 − a1b3, a1b2 − a2b1). (1, 2, 3) × (4, 5, 6) = (−3, 6, −3).
How do you find the angle between two vectors?
Take the inverse cosine of the dot product divided by the product of the magnitudes. Perpendicular vectors give 90°.
What is cosine similarity?
The cosine of the angle between two vectors. It ranges from −1 to 1 and ignores length, so it measures direction only.
What are the direction cosines of a vector?
The components divided by the magnitude, which are the cosines of the angles with each axis. Their squares add to 1. (1, 2, 2) gives 1/3, 2/3, 2/3.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.