Dot product
From CGAFaq
The dot product or scalar product of two vectors u = (u1, …, un) and v = (v1, …, vn) of the same n-dimensional real vector space is a scalar valued function defined as
- u·v = u1 v1 + ⋯ + un vn
Contents |
Properties
Important properties of the dot product are:
- u·v is linear in both u and v (bilinear)
- u·v = v·u (symmetric)
- u·u > 0 if u ≠ 0 (positive definite)
The dot product is closely related to distances and angles, and can be derived from the Pythagorean theorem by polarization. As is customary, write the Euclidean length of vector v as ‖v‖. Using the head-to-tail rule of vector addition, vectors u, v, and u+v form the sides of a triangle. The Pythagorean theorem tells us that if u and v are perpendicular (so we have a right triangle), then ‖u+v‖2 = ‖u‖2+‖v‖2. Restricting attention to 2D vectors for simplicity, we subtract the right side from the left to obtain a component formula
‖u+v‖2 − ‖u‖2 − ‖v‖2 = (u1+v1)2 + (u2+v2)2 − (u12 + u22) − (v12 + v22) = 2u1v1 + 2u2v2 = 2(u·v)
We draw the following conclusions:
- u·v = 0 implies either u = 0 or v = 0 or u and v are perpendicular
- u·v > 0 implies the angle between u and v is greater than 90°
- u·v < 0 implies the angle between u and v is less than 90°
- v·v = ‖v‖2
- u·v = ‖u‖ ‖v‖ cos θ, where θ is the angle between u and v
Using matrix multiplication and column vectors, the dot product can be written as u·v = uTv.
Inner product
The dot product of real vectors takes a slightly different form for complex vectors. Complex numbers w = a+bi have a real-valued squared magnitude given by w w*, where w* = a−bi is the complex conjugate of w. Accordingly, the complex formula is
- u1 v1* + ⋯ + un vn*
Because of the conjugation, this version is not quite linear in the second argument; thus it is not bilinear, but sesquilinear, where "sesqui-" means 1½. Also, instead of pure symmetry we have "conjugate symmetry", where swapping arguments conjugates the result.
This leads to the broader definition of a (hermitian) inner product, 〈u,v〉, which is any scalar-valued function of real or complex vectors that is:
- sesquilinear
- conjugate symmetric
- positive definite
Actually, it is enough to specify only left linearity, since conjugate symmetry then implies sesquilinearity.
Inner products make sense for infinite-dimensional vector spaces, not just finite-dimensional ones. For example, the CIE 1931 XYZ color space coordinates of a visible spectral curve are essentially computed by three inner products, one for each color component.
Euclidean length was used to define the dot product, and inner products can be used to define other norms. Thus if 〈u,v〉 is an inner product, then
- ‖v‖ = [〈v,v〉]½
always defines a norm. However, the converse is not true; for example, the ∞-norm ‖v‖∞ = MAX(|v1|,…,|vn|) has no corresponding inner product.
Despite their greater generality, norms derived from inner products obey three familiar relations:
- |〈u,v〉| ≤ ‖u‖ ‖v‖ (Schwarz inequality)
- ‖u+v‖ ≤ ‖u‖ + ‖v‖ (triangle inequality)
- ‖u+v‖2 + ‖u−v‖2 = 2 ‖u‖2 + 2 ‖v‖2 (parallelogram identity)
The Jordan-von Neumann theorem states that a norm ‖·‖ corresponds to some inner product if and only if it satisfies the parallelogram identity.
Polarizing any positive definite quadratic form yields an inner product. Polarizing an arbitrary quadratic form produces a symmetric bilinear form which may not be positive or definite; however, these can also be useful. For example, the inner product used in special relativity comes from the quadratic form x²+y²+z²−t².
Inner products, and the norms and quadratic forms derived from them, have a convenient expression in terms of matrices. A symmetric bilinear form over a finite-dimensional real vector space corresponds to an n×n symmetric matrix A. The formula
- (u,v) ↦ uT A v
defines an inner product from A. If A is an identity matrix we again arrive at the dot product.
Applications
If u is a unit vector, so that u·u = 1, then u(u·v) is the component of v in the direction of u. Geometrically, this drops a perpendicular from the tip of v onto the line determined by u. If (e1, …, en) is an orthonormal basis, then (v·e1, …, v·en) are the coordinates of v with respect to that basis. Using the complex version of the dot product, this immediate gives the equations for the discrete Fourier transform.
Another use for this projection is in calculating a reflection. Suppose u is a unit vector perpendicular to the desired mirror. The component of v parallel to u must be reversed to obtain its reflection, with the perpendicular component unchanged. This is accomplished by the formula v−2u(u·v), or the reflection matrix
- I − 2 u uT.
In computer graphics the dot product is often used for shading models, in particular the Lambertian shading model is just a dot product.
Other connections
The dot product has a natural interpretation in terms of quaternions (in fact it was first invented in such a way) and Clifford algebras.

