Compute the vector projection (projₓᵥ) and scalar projection (compₓᵥ) of vector v onto vector u. Visualize orthogonal decomposition, dot product, and angle.
The vector projection of v onto u (non-zero) is the orthogonal projection of v onto the line spanned by u. It represents the component of v that lies in the direction of u. Denoted proju v = ((v·u)/(u·u)) u. The scalar projection (or component) is compu v = (v·u)/|u|, which gives the signed length of the projection. This concept is fundamental in linear algebra, physics (force decomposition), and data science (dimension reduction).
proju v = \frac{v·u}{u·u} u , compu v = \frac{v·u}{|u|}
where dot product v·u = vₓuₓ + vᵧuᵧ, and |u| = √(uₓ² + uᵧ²).
Given vectors v and u, we want a scalar λ such that λu is the projection of v onto u, with residual vector (v - λu) perpendicular to u. Orthogonality condition: (v - λu)·u = 0 ⇒ v·u - λ (u·u) = 0 ⇒ λ = (v·u)/(u·u). Therefore proj = λu, and the perpendicular component = v - λu. The scalar projection length equals |proj| = |λ|·|u| = |v·u|/|u| if considering absolute length; but signed value preserves direction sign. This decomposition is unique and widely used in Gram–Schmidt process.
All calculations are performed with double-precision floating-point arithmetic using standard vector formulas. The interactive graph uses canvas coordinate mapping from world coordinates to screen pixels with dynamic padding and scaling. Vector arrows are drawn with triangle heads. Orthogonal decomposition is shown via a dashed segment connecting the tip of projection to the tip of vector v, highlighting the residual component. The tool treats u ≈ 0 as an error; the user is notified.
| Vector v | Vector u | Vector Projection (proj) | Scalar Projection | Angle (°) |
|---|---|---|---|---|
| (4, 3) | (2, 1) | (4.4, 2.2) | 4.919 | 10.30° |
| (5, 2) | (1, 0) | (5, 0) | 5.00 | 21.80° |
| (3, 4) | (0, 1) | (0, 4) | 4.00 | 53.13° |
| (1, 2) | (2, -1) | (0, 0) | 0.00 | 90.0° |