Vectors: The Complete Guide
What Is a Vector?
A vector is a mathematical object with both magnitude (length) and direction. Unlike scalars (plain numbers like 5 or −3.2), vectors carry directional information. In 2D, a vector is represented as A = (a₁, a₂); in 3D, as A = (a₁, a₂, a₃). Vectors describe forces, velocities, displacements, electric fields, and gradients. The standard basis vectors are î = (1,0,0), ĵ = (0,1,0), and k̂ = (0,0,1), so any vector A = a₁î + a₂ĵ + a₃k̂.
|A| = √(a₁² + a₂² + a₃²)
 = A / |A| (unit vector)
Vector Addition and Subtraction
Vector addition adds corresponding components: A + B = (a₁+b₁, a₂+b₂, a₃+b₃). Geometrically, this is the "tip-to-tail" method: place vector B's tail at vector A's head, and the sum points from A's tail to B's head. This also forms the diagonal of the parallelogram formed by A and B. Subtraction reverses B first: A − B = A + (−B) = (a₁−b₁, a₂−b₂, a₃−b₃). Vector addition is commutative (A+B = B+A) and associative ((A+B)+C = A+(B+C)).
A + B = (3+1, 4+5) = (4, 9).
A − B = (3−1, 4−5) = (2, −1).
Dot Product (Scalar Product)
The dot product A·B = a₁b₁ + a₂b₂ + a₃b₃ produces a scalar. Geometrically, A·B = |A||B|cos(θ), where θ is the angle between the vectors. Key properties: if A·B = 0, the vectors are perpendicular (orthogonal). If A·B > 0, they point in roughly the same direction; if A·B < 0, roughly opposite directions. The dot product is used in projection, work calculations (W = F·d), lighting computations in computer graphics (Lambert's cosine law), and determining orthogonality in linear algebra.
θ = arccos(A·B / (|A||B|))
Perpendicular when A·B = 0
Cross Product (Vector Product)
The cross product A × B is defined only in 3D and produces a vector perpendicular to both A and B. The formula is A×B = (a₂b₃−a₃b₂, a₃b₁−a₁b₃, a₁b₂−a₂b₁). Its magnitude |A×B| = |A||B|sin(θ), which equals the area of the parallelogram formed by A and B. The direction follows the right-hand rule: curl fingers from A to B, and your thumb points in the direction of A×B. The cross product is anti-commutative: A×B = −(B×A).
Magnitude and Unit Vectors
The magnitude (or norm) of vector A is |A| = √(a₁² + a₂² + a₃²), which is the length of the vector. A unit vector has magnitude exactly 1 and preserves direction: Â = A/|A|. Unit vectors are essential for specifying directions without magnitude. Every non-zero vector can be decomposed as A = |A|·Â (magnitude × direction). The zero vector (0,0,0) has magnitude 0 and no defined direction.
Angle Between Vectors
The angle between two vectors is found using θ = arccos(A·B / (|A||B|)). The result is always between 0° and 180°. At 0°, vectors are parallel (same direction); at 90°, perpendicular; at 180°, antiparallel (opposite directions). This formula works in any dimension. In machine learning, the cosine similarity cos(θ) = A·B / (|A||B|) measures how similar two vectors are, widely used in text analysis and recommendation systems.
Scalar Multiplication and Projection
Scalar multiplication kA = (ka₁, ka₂, ka₃) scales a vector by factor k. If k > 1, the vector stretches; if 0 < k < 1, it shrinks; if k < 0, it reverses direction. The scalar projection of A onto B is comp_B(A) = A·B/|B|, which gives the signed length of A's shadow on B. The vector projection is proj_B(A) = (A·B/|B|²)B, a vector along B representing A's component in B's direction.
Vectors in Physics and Engineering
Vectors are the language of physics. Force, velocity, acceleration, momentum, and electric/magnetic fields are all vector quantities. Newton's second law F = ma is a vector equation. The work done by a force is W = F·d (dot product). Torque is τ = r × F (cross product). In electromagnetism, Maxwell's equations use vector calculus extensively. In computer graphics, vectors define positions, normals, lighting directions, and camera orientations. In machine learning, data points are represented as high-dimensional vectors.
Vectors in Computer Science
Beyond mathematics, vectors power modern technology. In computer graphics, every vertex, normal, and ray is a vector. In machine learning, word embeddings (Word2Vec, GPT) represent words as high-dimensional vectors where cosine similarity captures semantic meaning. In game development, physics engines use vectors for collision detection, projectile motion, and camera controls. In data science, feature vectors describe data points, and operations like dot products underpin neural network computations.
How to Use This Calculator
Choose an operation (Addition, Subtraction, Dot Product, Cross Product, Magnitude, Unit Vector, Angle, or Scalar Multiplication). Select 2D or 3D mode. Enter vector components and click Calculate. For single-vector operations (Magnitude, Unit Vector), only Vector A is needed. For Cross Product, 3D mode is automatically selected. The visualization shows vectors on a coordinate grid with labeled axes, and the step-by-step section walks through every calculation.