CalcMountain

Dot Product Calculator

Enter the components of two vectors to find their dot product, the angle between them, and whether they are orthogonal. Supports 2D and 3D vectors.

The dot product (also called scalar product or inner product) is a fundamental operation on two vectors that produces a single number (scalar). Written A · B or ⟨A, B⟩, it captures how "aligned" two vectors are. Maximum when parallel (same direction), zero when perpendicular, negative when pointing opposite ways.

The formula is simple: multiply corresponding components and sum. For A = (a₁, a₂, a₃) and B = (b₁, b₂, b₃): A · B = a₁b₁ + a₂b₂ + a₃b₃. The result is geometric: A · B = |A| × |B| × cos(θ), where θ is the angle between vectors. This gives us a way to find angles, projections, work done by forces, and similarity in high-dimensional spaces.

Dot product is the foundation of countless mathematical and computational tools: - **Physics**: work done by a force is W = F · d (force projected onto displacement). - **Computer graphics**: lighting calculations use dot product (Lambert's cosine law). - **Machine learning**: cosine similarity ranks documents/items by direction similarity. - **Statistics**: correlation is essentially a normalized dot product. - **Engineering**: projecting forces onto axes, decomposing motion.

Unlike the cross product, dot product works in any dimension. In 100-dimensional feature space (text embeddings), the dot product still measures alignment via cos(θ). This makes it the workhorse of modern AI and information retrieval systems.

Common applications: physics (work, projection), computer graphics (lighting, shading), machine learning (similarity), statistics (correlation), engineering (force decomposition), and any analysis involving directional relationships between quantities.

Inputs

Results

Dot Product (A·B)

32

|A| (magnitude)

3.741657

|B| (magnitude)

8.774964

Angle Between

12.933154° (0.225726 rad)

Orthogonal?

No

Last updated:

Formula

**Dot product (algebraic):** A · B = a₁b₁ + a₂b₂ + a₃b₃ + ... + aₙbₙ For 2D: A · B = a₁b₁ + a₂b₂ For 3D: A · B = a₁b₁ + a₂b₂ + a₃b₃ **Dot product (geometric):** A · B = |A| × |B| × cos(θ) Where: - |A|, |B| = magnitudes - θ = angle between vectors (0 to π) **Finding angle between vectors:** cos(θ) = (A · B) / (|A| × |B|) θ = arccos((A · B) / (|A| × |B|)) **Worked example: 3D dot product** A = (1, 2, 3), B = (4, 5, 6). A · B = 1×4 + 2×5 + 3×6 = 4 + 10 + 18 = 32 |A| = √(1 + 4 + 9) = √14 ≈ 3.742 |B| = √(16 + 25 + 36) = √77 ≈ 8.775 cos(θ) = 32 / (3.742 × 8.775) ≈ 32 / 32.835 ≈ 0.975 θ ≈ arccos(0.975) ≈ 12.93° Vectors are nearly aligned. **Special cases:** - A · B > 0: angle < 90° (acute, same general direction). - A · B = 0: perpendicular (90°), orthogonal. - A · B < 0: angle > 90° (obtuse, somewhat opposite). - A · A = |A|² (vector dotted with itself = magnitude squared). **Properties:** | Property | Statement | |---|---| | Commutative | A · B = B · A | | Distributive | A · (B + C) = A · B + A · C | | Scalar multiplication | (kA) · B = k(A · B) | | Magnitude | \|A\| = √(A · A) | | Cauchy-Schwarz | \|A · B\| ≤ \|A\| × \|B\| | **Standard dot products:** i · j = 0 j · k = 0 k · i = 0 i · i = j · j = k · k = 1 **Projection (component of A onto B):** scalar projection = (A · B) / |B| vector projection = ((A · B) / (B · B)) × B The projection tells how much of A "points in the direction" of B. **Worked example: physics work** Force F = (10, 0, 0) N. Displacement d = (3, 4, 0) m. W = F · d = 10×3 + 0×4 + 0×0 = 30 J Only the x-component of displacement matters (force is along x). Total displacement of 5 m, but only 3 m in force direction → 30 J of work. **Worked example: orthogonality test** Are A = (3, 4) and B = (-4, 3) perpendicular? A · B = 3×(-4) + 4×3 = -12 + 12 = 0 Yes! Dot product = 0 means perpendicular. **Worked example: angle calculation** Find angle between A = (1, 0, 0) and B = (1, 1, 0). A · B = 1×1 + 0×1 + 0×0 = 1 |A| = 1, |B| = √2 cos(θ) = 1/√2 ≈ 0.707 θ = 45° Vectors are 45° apart. **Cross product vs dot product:** | Property | Dot | Cross | |---|---|---| | Result | Scalar | Vector | | Symmetric | Yes (commutative) | No (anti-commutative) | | Parallel vectors | Maximum (= \|A\|\|B\|) | Zero | | Perpendicular | Zero | Maximum | | Formula | a₁b₁ + a₂b₂ + a₃b₃ | (a₂b₃-a₃b₂, ...) | | Geometric | \|A\|\|B\|cos(θ) | \|A\|\|B\|sin(θ) | | Dimensions | Any | 3D only | **Cosine similarity (ML):** For high-dimensional vectors (document embeddings, item features): similarity = (A · B) / (|A| × |B|) = cos(θ) Ranges from -1 (opposite) to 1 (same direction). Used in: - **Document ranking**: search engines. - **Recommendation systems**: similar items have high cosine similarity. - **Word embeddings**: word2vec, BERT. - **Image retrieval**: visual similarity. **Physics applications:** **Work done by a force:** W = F · d Force component along displacement direction does the work. **Power:** P = F · v Force component along velocity = rate of work. **Magnetic flux:** Φ = B · A Magnetic field component perpendicular to area. **Computer graphics:** **Lambert's law (diffuse lighting):** brightness = max(0, N · L) Where N = surface normal (unit vector), L = direction to light. - Surface facing light: high dot product, bright. - Surface edge-on: low dot product, dim. - Surface facing away: negative dot product, dark (clamp to 0). **Backface culling:** If (camera-to-face) · (face normal) > 0: face is back-facing, don't render. **Statistical correlation:** Pearson correlation r = (Σ(xᵢ-μₓ)(yᵢ-μᵧ)) / (σₓσᵧ × n) Essentially a normalized dot product of mean-centered data vectors. **Geometric meaning of dot product:** - |A · B| is the "alignment" of A and B. - A · B / |B| is the length of projection of A onto B's direction. - For unit vectors: A · B = cos(θ). **Quadratic form (matrix dot product):** For column vectors x, y and matrix A: x^T A y = generalized inner product. Used in: optimization (quadratic programming), physics (Lagrangian). **Software:** - **Python (NumPy)**: np.dot(a, b) or a @ b - **MATLAB**: dot(a, b) or a transpose * b - **C++ (Eigen)**: a.dot(b) - **JavaScript (THREE.js, GL-Matrix)**: built-in - **OpenGL/HLSL shaders**: dot(a, b) for lighting **Common applications:** - **Physics**: work, projections, forces on inclines. - **Computer graphics**: lighting, shadows, shading. - **Machine learning**: similarity, classification. - **Search engines**: document ranking by relevance. - **Recommendation systems**: similar items/users. - **Audio**: spectral correlation analysis. - **Image processing**: template matching. - **Robotics**: orientation alignment. - **Statistics**: correlation, principal component analysis.

How to use this calculator

  1. Choose 2D or 3D dimensions.
  2. Enter components of vector A.
  3. Enter components of vector B.
  4. Calculator returns dot product, magnitudes, and angle.
  5. Result interpretation: 0 = perpendicular, positive = aligned, negative = opposite.
  6. For unit vectors: dot product = cos(θ) directly.

Worked examples

Work calculation

**Scenario:** Force F = (50, 0, 0) N pushes block 10 m at 30° below horizontal: displacement d = (8.66, 0, -5). **Calculation:** W = F · d = 50×8.66 + 0×0 + 0×(-5) = 433 J. **Result:** ~433 J of work. Only horizontal component of displacement matters (force is horizontal). Total displacement is 10 m, but work uses projection onto force direction (8.66 m).

Surface lighting

**Scenario:** Surface normal N = (0, 1, 0) (pointing up). Light direction L = (0.7, 0.7, 0). Brightness? **Calculation:** N · L = 0×0.7 + 1×0.7 + 0×0 = 0.7. **Result:** Brightness = 0.7 (70% of maximum). Surface is angled 45° from light direction. Used in computer graphics for Lambertian (diffuse) shading. For complete light model: also includes ambient, specular components.

Cosine similarity for recommendations

**Scenario:** User A likes [movies, books, tech]: vector (3, 5, 2). User B likes [movies, books, tech]: vector (1, 4, 0). Similarity? **Calculation:** A · B = 3 + 20 + 0 = 23. |A| = √38 ≈ 6.16. |B| = √17 ≈ 4.12. cos(θ) = 23/(6.16 × 4.12) ≈ 0.907. **Result:** Cosine similarity 0.907 (very similar — both like books and movies). Used in recommendation engines: high similarity users get each other's recommendations. Below 0.5 typically means low similarity.

When to use this calculator

**Use dot product for:**

- **Finding angles between vectors**: cos(θ) = A·B / (|A||B|). - **Testing perpendicularity**: A · B = 0 means perpendicular. - **Physics work**: W = F · d. - **Computer graphics**: lighting calculations. - **Machine learning**: cosine similarity for items/text. - **Statistics**: correlation analysis. - **Projections**: how much of A points in direction B. - **Decomposing vectors**: into parallel and perpendicular components.

**Dot vs cross product:**

Use dot when you need: - A scalar number. - Measure of alignment. - Angle between vectors. - Work or projection.

Use cross when you need: - A perpendicular vector. - Rotational quantity (torque, angular momentum). - Surface normal from edges. - Area of parallelogram.

**Geometric interpretation:**

- A · B = |A||B|cos(θ) measures "alignment". - Magnitude × magnitude × cosine. - Maximum when parallel: |A| × |B|. - Zero when perpendicular. - Minimum (most negative) when antiparallel: -|A| × |B|.

**Cosine similarity intuition:**

For unit vectors: A · B = cos(θ) directly. - 1.0: identical direction. - 0.5: 60° apart. - 0.0: perpendicular. - -0.5: 120° apart. - -1.0: opposite directions.

In ML, often used for word embeddings, document vectors, image features.

**Higher dimensions:**

Dot product works in any dimension by summing products of corresponding components: A · B = Σᵢ aᵢ × bᵢ

In 100-D feature space (text embeddings, image features): same formula, just more terms.

**Physical interpretation:**

For force and displacement: W = F · d = |F||d|cos(θ)

- θ = 0: full work (force aligned with motion). - θ = 90°: no work (force perpendicular to motion). - θ = 180°: negative work (force opposes motion).

Lifting weight: force up, displacement up → positive work. Carrying horizontally: force up, displacement horizontal → zero work.

**Common applications:**

- **CAD**: angle between edges or surfaces. - **Robotics**: aligning end-effector with target. - **Aerospace**: thrust vector vs velocity (for force calculations). - **Navigation**: heading correction. - **Audio**: signal correlation analysis. - **Image recognition**: template matching by dot product. - **Information retrieval**: ranking documents.

**Software:**

- Python NumPy: np.dot(a, b) - MATLAB: dot(a, b) - Most languages: simple loop or built-in.

**Pitfalls:**

- **Forgetting dot is scalar**: result is single number, not vector. - **Wrong dimension**: vectors must have same length. - **Sign**: positive ≠ "magnitude", just means same general direction. - **Cos(θ) ambiguity**: 0 < θ < π only; can't distinguish A vs -A. - **Unit vectors**: simplify A · B = cos(θ); always check magnitudes. - **Order doesn't matter** (commutative) — but for projection direction, it does.

Common mistakes to avoid

  • Confusing dot product (scalar) with cross product (vector).
  • Forgetting to sum the products of corresponding components.
  • Using formula on vectors of different dimensions.
  • Wrong angle interpretation (cos can be positive or negative).
  • Confusing dot product with element-wise multiplication.
  • For unit vectors: forgetting magnitudes are 1, so A · B = cos(θ).
  • Calculating angle for parallel vectors (cos = 1 or -1, need to check sign).
  • Using radians vs degrees inconsistently in angle output.

Frequently Asked Questions

Sources & further reading

SponsoredShop Top Deals on AmazonSupport CalcMountain — browse top-rated products at no extra cost to you.

Related Calculators