This 2D vector calculator takes two planar vectors a and b and returns every common operation at once: their sum and difference, the dot product, the scalar cross product, each vector’s magnitude, and the angle between them. It is built for students, engineers and game developers who need a quick, correct check of vector arithmetic without reaching for a graphing calculator.
How it works
Given a = (aₓ, aᵧ) and b = (bₓ, bᵧ), the tool evaluates:
- Sum / difference:
a ± b = (aₓ ± bₓ, aᵧ ± bᵧ)— component by component. - Dot product:
a·b = aₓbₓ + aᵧbᵧ(zero when perpendicular). - Cross product (scalar):
a×b = aₓbᵧ − aᵧbₓ— the z-component of the 3D cross product and the signed area of the parallelogram the vectors span. - Magnitudes:
|a| = √(aₓ² + aᵧ²), likewise for|b|. - Angle:
θ = arccos((a·b) / (|a||b|)), in degrees, clamped to the valid −1…1 range to avoid rounding errors.
Example
For a = (3, 4) and b = (1, 2):
| Result | Value |
|---|---|
| a + b | (4, 6) |
| a − b | (2, 2) |
| a · b (dot) | 11 |
| a × b (cross) | 2 |
| |a|, |b| | 5, 2.236 |
| Angle between | 10.3° |
The dot product 11 = 3·1 + 4·2, and the cross product 2 = 3·2 − 4·1. Everything is computed in your browser — no data leaves your device.
What the outputs are useful for
Each result has a specific practical application depending on the problem you are solving:
Sum and difference are the workhorses of movement and force problems. Adding velocity vectors gives a resultant velocity; subtracting a position vector from another gives the displacement vector pointing from one to the other.
Dot product tells you about alignment. A dot product of zero confirms perpendicularity — useful in game physics to check if a surface normal is at right angles to a velocity vector, or in graphics to determine if a light source faces a surface. A negative dot product means the vectors point in generally opposite directions; positive means they lean the same way.
Scalar cross product (2D) gives the signed area of the parallelogram the two vectors span — which is twice the area of the triangle they form. In 2D geometry this is how you test if a point is to the left or right of a directed line segment, which is the basis of many polygon-winding and hit-test algorithms. A positive value means b is counter-clockwise from a in standard orientation.
Magnitudes are needed whenever you want to normalize a vector to unit length (divide each component by the magnitude), compare speeds, or find the length of a displacement.
Angle between vectors shows how much two directions diverge. This is used in lighting models (the angle between the surface normal and the light direction determines how brightly a surface is lit), navigation (angle between heading and target), and machine-learning feature comparison (cosine similarity, which relates directly to the dot product and magnitudes).
Avoiding the arccos domain error
When both vectors have very similar directions, floating-point rounding can push the ratio (a·b) / (|a||b|) just above 1.0 or just below −1.0, which makes arccos return NaN. The tool clamps the input to the range [−1, 1] before calling arccos so you always get a valid angle rather than an error.