Dimension
Vector a
a
=
(
,
,
)
Vector b
b
=
(
,
,
)
Vector Operations Reference
| Operation | Formula | Result Type |
|---|---|---|
| Addition | a + b = (ax+bx, ay+by, az+bz) | Vector |
| Subtraction | a − b = (ax−bx, ay−by, az−bz) | Vector |
| Magnitude | |a| = √(ax²+ay²+az²) | Scalar |
| Unit Vector | â = a / |a| | Vector (|â|=1) |
| Dot Product | a·b = ax·bx + ay·by + az·bz = |a||b|cos(θ) | Scalar |
| Cross Product | a×b = (ay·bz−az·by, az·bx−ax·bz, ax·by−ay·bx) | Vector (3D only) |
| Angle Between | θ = arccos(a·b / (|a|·|b|)) | Scalar (0°–180°) |
| Projection of a onto b | proj_b(a) = (a·b/|b|²)·b | Vector |
| Scalar projection | comp_b(a) = a·b / |b| | Scalar |
Dot Product vs Cross Product
Dot product (a·b): A scalar that equals |a||b|cos(θ). It measures how much two vectors point in the same direction. If a·b = 0 the vectors are perpendicular (orthogonal). Used to find angles, work done by a force, and vector projections.
Cross product (a×b): Only defined in 3D. Produces a vector perpendicular to both a and b, with magnitude |a||b|sin(θ). The direction follows the right-hand rule. Its magnitude equals the area of the parallelogram spanned by a and b. Used in physics for torque, angular momentum, and surface normals in 3D graphics.
Applications of Vectors
- Physics: Forces, velocity, acceleration, momentum and torque are all vectors. Newton's second law F = ma uses vector addition to combine forces.
- 3D Computer Graphics: Surface normals (cross product), lighting calculations (dot product), camera transformations and collision detection all rely on vector operations.
- Navigation: GPS displacement vectors, wind correction angles, and ship heading calculations use vector addition and dot products.
- Machine Learning: Data points are vectors in high-dimensional space; cosine similarity (normalised dot product) measures document or embedding similarity.
Frequently Asked Questions
The dot product (a·b) produces a scalar equal to |a||b|cos(θ). The cross product (a×b) produces a vector perpendicular to both inputs with magnitude |a||b|sin(θ), and is only defined in 3D. Use the dot product for angles and projection; use the cross product for normals, torque, and finding perpendicular vectors.
Use θ = arccos(a·b / (|a|·|b|)). Compute the dot product, divide by the product of the magnitudes to get cos(θ), then take the inverse cosine. The result is always between 0° and 180°. If the dot product is negative the angle is obtuse (greater than 90°).
A unit vector has magnitude exactly 1 and encodes direction only. To compute â from a, divide each component by the magnitude: â = a / |a|. The three standard unit vectors (î, ĵ, k̂) point along the x, y, z axes. Unit vectors are essential in physics (direction of forces) and 3D graphics (surface normals).
The cross product is strictly a 3D operation. In 2D we treat vectors as 3D with z = 0, giving a×b = (0, 0, ax·by − ay·bx). Only the z-component is non-zero. This scalar ax·by − ay·bx equals the signed area of the parallelogram formed by a and b, and can tell you whether b is to the left or right of a.