CalcOpenly

Vector calculator

Dot and cross products of two vectors in 2D or 3D, their magnitudes, the angle between them and the projection of one onto the other, with a drawing.

Updated Checked against 5 worked examples

Try
Dot product a · b
Dot product a · b: 32
Shown to up to 10 decimal places, half-up
Cross product a × b
(−3, 6, −3)
|a × b| (parallelogram area)
7.3484692283
|a|
3.7416573868
|b|
8.7749643874
Angle between a and b
12.93315449°
Angle in radians
0.2257261286rad
Scalar projection of a onto b
3.6467384467
Vector projection of a onto b
(1.662338, 2.077922, 2.493506)

a · b = 32, so the vectors are 12.9332° apart; the parallelogram they span has area 7.34847.

Vectors a, b and a × b (oblique view)

xyzaba × b
How it's calculated S
  1. Dot product

    a⋅b=1⋅4+2⋅5+3⋅6=32\mathbf a\cdot\mathbf b = 1\cdot4 + 2\cdot5 + 3\cdot6 = 32
  2. Cross product

    a×b=(aybz−azbyazbx−axbzaxby−aybx)=(−36−3)\mathbf a\times\mathbf b = \begin{pmatrix} a_y b_z - a_z b_y \\ a_z b_x - a_x b_z \\ a_x b_y - a_y b_x \end{pmatrix} = \begin{pmatrix}-3 \\ 6 \\ -3\end{pmatrix}
  3. Magnitudes

    ∣a∣=12+22+32=3.74165738677,∣b∣=42+52+62=8.77496438739|\mathbf a| = \sqrt{1^2 + 2^2 + 3^2} = 3.74165738677,\qquad |\mathbf b| = \sqrt{4^2 + 5^2 + 6^2} = 8.77496438739
  4. Angle between them

    θ=atan2⁡(∣a×b∣, a⋅b)=atan2⁡(7.348469228, 32)=12.9331544919∘\theta = \operatorname{atan2}\left(|\mathbf a\times\mathbf b|,\ \mathbf a\cdot\mathbf b\right) = \operatorname{atan2}(7.348469228,\ 32) = 12.9331544919^\circ

    Equivalent to arccos(a·b / |a||b|), but stays accurate when the vectors are nearly parallel.

  5. Projection of a onto b

    comp⁡ba=a⋅b∣b∣=3.64673844671,proj⁡ba=3277 b=(1.6623376622.0779220782.493506494)\operatorname{comp}_{\mathbf b}\mathbf a = \frac{\mathbf a\cdot\mathbf b}{|\mathbf b|} = 3.64673844671,\qquad \operatorname{proj}_{\mathbf b}\mathbf a = \frac{32}{77}\,\mathbf b = \begin{pmatrix}1.662337662 \\ 2.077922078 \\ 2.493506494\end{pmatrix}

About the vector calculator

The dot product multiplies matching components and adds them, a · b = a₁b₁ + a₂b₂ + a₃b₃. The cross product of two 3D vectors is a vector perpendicular to both, and its length equals the area of the parallelogram they span. The angle between the vectors is computed as θ = atan2(|a × b|, a · b), which equals arccos(a · b / |a||b|) but stays accurate for nearly parallel vectors, and the projection of a onto b is (a · b / |b|²) b.

Physics (work and torque), 3D graphics and linear algebra are the usual uses. The default vectors a = (1, 2, 3) and b = (4, 5, 6) give a · b = 32, a × b = (−3, 6, −3) and an angle of about 12.93°.

A dot product of 0 means the vectors are perpendicular; a zero cross product means they are parallel or one is zero. In 2D mode both vectors lie in the xy-plane, so their cross product points along z: (3, 4) × (4, −3) = (0, 0, −25).

Worked examples

a = (1, 2, 3), b = (4, 5, 6)

Dimensions
3D
a — x
1
a — y
2
a — z
3
b — x
4
b — y
5
b — z
6
Dot product a · b
32
Cross product a × b
(−3, 6, −3)
|a|
3.7416573868
Angle between a and b
12.93315449 °
|a × b| (parallelogram area)
7.3484692283

Checked against: Hand calculation; Python decimal √14, √54 and atan2(√54, 32) in degrees (hp.py)

Perpendicular 2D vectors (3, 4) and (4, −3)

Dimensions
2D
a — x
3
a — y
4
b — x
4
b — y
-3
Dot product a · b
0
Angle between a and b
90 °
Cross product a × b
(0, 0, −25)

Checked against: 3·4 + 4·(−3) = 0; 3·(−3) − 4·4 = −25

Parallel vectors (edge case)

Dimensions
3D
a — x
1
a — y
2
a — z
3
b — x
2
b — y
4
b — z
6
Cross product a × b
(0, 0, 0)
Angle between a and b
0 °
Dot product a · b
28

Checked against: b = 2a, so a × b = 0 and θ = 0

Projection of (2, 3) onto (4, 0)

Dimensions
2D
a — x
2
a — y
3
b — x
4
b — y
0
Scalar projection of a onto b
2
Vector projection of a onto b
(2, 0)
Angle between a and b
56.30993247 °

Checked against: a·b/|b| = 8/4; angle atan2(3, 2) = 56.3099324740202…° (Python math.degrees)

Questions

How do you calculate the dot product of two vectors?

Multiply corresponding components and add the results: a · b = a₁b₁ + a₂b₂ + a₃b₃. For (1, 2, 3) · (4, 5, 6) that is 4 + 10 + 18 = 32. The dot product also equals |a||b| cos θ, so it is positive when the angle is under 90°, 0 at exactly 90° and negative beyond it: (1, 0) · (−2, 0) = −2.

How do you calculate the cross product?

For a = (a₁, a₂, a₃) and b = (b₁, b₂, b₃), a × b = (a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁). For (1, 2, 3) × (4, 5, 6) that gives (12 − 15, 12 − 6, 5 − 8) = (−3, 6, −3). The result is perpendicular to both vectors, follows the right-hand rule, and changes sign if the order is swapped: b × a = (3, −6, 3).

How do you find the angle between two vectors?

Use cos θ = (a · b)/(|a||b|). For (1, 2, 3) and (4, 5, 6), cos θ = 32/(√14 × √77) ≈ 0.974632, so θ ≈ 12.93°. Near 0° or 180° the arccos form loses accuracy, so the calculator uses the equivalent θ = atan2(|a × b|, a · b), the form William Kahan recommends in his notes on floating-point roundoff.

What does it mean if the dot product is zero?

The two vectors are perpendicular (orthogonal), provided neither is the zero vector. (3, 4) · (4, −3) = 12 − 12 = 0, so those vectors meet at exactly 90°. In physics the same test shows that a force at right angles to the motion does no work, since work is the dot product of force and displacement.

What is the difference between scalar and vector projection?

The scalar projection of a onto b is the signed length of a along b, a · b / |b|; the vector projection is that length times the unit vector of b, (a · b / |b|²) b. Projecting (2, 3) onto (4, 0) gives a scalar projection of 8/4 = 2 and a vector projection of (2, 0). A negative scalar projection means a points partly against b.

How accurate is the vector calculator?

Accuracy depends on your inputs and the method's assumptions. Decimal arithmetic uses 50 significant digits, but estimates, numerical methods and source data can be less precise; the displayed rounding does not remove those limits. It is checked against 5 worked examples whose answers come from independent sources; for example, “a = (1, 2, 3), b = (4, 5, 6)” is checked against Hand calculation; Python decimal √14, √54 and atan2(√54, 32) in degrees (hp.py).

Where does the method come from?

Wolfram MathWorld — Dot Product; Wolfram MathWorld — Cross Product; W. Kahan, How futile are mindless assessments of roundoff in floating-point computation? §12 — angles via atan2 rather than arccos.

About this calculator

a⋅b=∑aibiθ=atan2⁡(∣a×b∣, a⋅b)proj⁡ba=a⋅b∣b∣2 b\begin{gathered} \mathbf a\cdot\mathbf b = \sum a_i b_i \\[6pt] \theta = \operatorname{atan2}(|\mathbf a\times\mathbf b|,\ \mathbf a\cdot\mathbf b) \\[6pt] \operatorname{proj}_{\mathbf b}\mathbf a = \frac{\mathbf a\cdot\mathbf b}{|\mathbf b|^2}\,\mathbf b \end{gathered}

Sources

  1. Wolfram MathWorld — Dot Product
  2. Wolfram MathWorld — Cross Product
  3. W. Kahan, How futile are mindless assessments of roundoff in floating-point computation? §12 — angles via atan2 rather than arccos

Checked against references

5 worked examples with independently sourced answers ship with this calculator. They run in the test suite; you can run them here too.

Related calculators

Allow optional Google Analytics to measure page visits? Calculators work either way. Privacy and choices

Optional analytics: off.