Vectors in two and three dimensions
A vector has a size and a direction, and is written with its components: (3, 4) in a plane, or (1, 2, 3) in space. Vectors describe displacements, velocities, forces and directions in computer graphics. This calculator takes two vectors u and v and computes the operations used most often in math, physics and engineering.
The formulas
- Magnitude: |u| = √(uₓ² + uᵧ² + u_z²)
- Dot product: u · v = uₓvₓ + uᵧvᵧ + u_zv_z
- Angle: θ = arccos(u · v ÷ (|u| |v|))
- Cross product: u × v = (uᵧv_z − u_zvᵧ, u_zvₓ − uₓv_z, uₓvᵧ − uᵧvₓ)
- Scalar projection of u on v: u · v ÷ |v|
In 2D, the calculator treats the vectors as lying in the xy-plane, so the cross product points along z.
Worked example in 2D
u = (3, 4) and v = (5, 0).
- |u| = √(9 + 16) = 5 and |v| = 5.
- u · v = 3 × 5 + 4 × 0 = 15.
- θ = arccos(15 ÷ 25) = arccos 0.6 = 53.13°.
- Cross product: (0, 0, 3 × 0 − 4 × 5) = (0, 0, −20), so the parallelogram they span has an area of 20.
- The projection of u on v is 15 ÷ 5 = 3: the shadow of u along the x-axis.
Worked example in 3D
u = (1, 2, 3) and v = (4, 5, 6) give a dot product of 32, magnitudes of 3.742 and 8.775, an angle of 12.93°, and a cross product of (−3, 6, −3) with a length of 7.348.
What the dot product tells you
| Dot product | Angle | Meaning |
|---|---|---|
| positive | less than 90° | the vectors point roughly the same way |
| zero | 90° | perpendicular |
| negative | more than 90° | they point roughly in opposite directions |
In physics, the work done by a force is the dot product of the force and the displacement: only the part of the force along the motion does work.
What the cross product tells you
The cross product is perpendicular to both vectors, following the right-hand rule, and its length is |u| |v| sin θ, the area of the parallelogram. It is zero when the vectors are parallel. It gives the normal to a surface in 3D graphics, the torque of a force, and the force on a moving charge in a magnetic field.
Tips
Use consistent units for all components. To get a unit vector, divide each component by the magnitude. The dot product is commutative (u · v = v · u), but the cross product is not: v × u is the opposite of u × v.