{
  "id": "orthogonal-projection",
  "version": "86fa22af513d",
  "status": "published",
  "name": "Orthogonal Projection Calculator",
  "question": "What is the orthogonal projection?",
  "summary": "Projects vector a onto vector b: the orthogonal (vector) projection in exact fractions, the scalar projection, the part of a orthogonal to b, and the angle between them.",
  "category": "math",
  "subcategory": "linear-algebra",
  "url": "https://www.acalculator.org/math/orthogonal-projection-calculator",
  "markdown": "https://www.acalculator.org/math/orthogonal-projection-calculator.md",
  "kind": "function",
  "method": "proj_b a = (a · b ÷ b · b) × b; comp_b a = a · b ÷ ‖b‖; the orthogonal part is a − proj_b a.",
  "assumptions": [
    "Vectors with 2 to 10 components, the same number in a and b; b is not the zero vector.",
    "Every number is read exactly as typed (0.5 is 1/2), so the projection and the orthogonal part are exact fractions.",
    "The scalar projection and the angle use square roots, so they are double-precision numbers."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "Vector a (to project)",
        "description": "The vector you project, such as 3, 5, 1.",
        "type": "array",
        "items": {
          "type": "number"
        }
      },
      "b": {
        "title": "Vector b (onto)",
        "description": "The vector you project onto, with as many components as a. It cannot be all zeros.",
        "type": "array",
        "items": {
          "type": "number"
        }
      }
    }
  },
  "outputs": {
    "projection": {
      "label": "Projection of a onto b",
      "description": "proj_b a = (a · b ÷ b · b) × b, as exact fractions.",
      "format": "text"
    },
    "decimal": {
      "label": "Projection in decimals",
      "description": "The same projection with each component to 6 significant digits.",
      "format": "text"
    },
    "scalar": {
      "label": "Scalar projection",
      "description": "comp_b a = a · b ÷ ‖b‖: the signed length of the projection.",
      "format": "number"
    },
    "orthogonal": {
      "label": "Part of a orthogonal to b",
      "description": "a − proj_b a, as exact fractions: it is at a right angle to b.",
      "format": "text"
    },
    "factor": {
      "label": "Multiple of b",
      "description": "a · b ÷ b · b: the projection is this number times b.",
      "format": "text"
    },
    "dot": {
      "label": "Dot product a · b",
      "description": "a₁b₁ + a₂b₂ + … + aₙbₙ.",
      "format": "number"
    },
    "angle": {
      "label": "Angle between a and b",
      "description": "arccos(a · b ÷ (‖a‖ ‖b‖)) in degrees. None when a is the zero vector.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": [
        3,
        5,
        1
      ],
      "b": [
        -1,
        4,
        3
      ]
    },
    "outputs": {
      "projection": "⟨−10/13, 40/13, 30/13⟩",
      "decimal": "⟨−0.769231, 3.07692, 2.30769⟩",
      "scalar": 3.922322702763681,
      "orthogonal": "⟨49/13, 25/13, −17/13⟩",
      "factor": "10/13",
      "dot": 20,
      "angle": 48.47142092270009
    },
    "text": "The projection of a onto b is ⟨−10/13, 40/13, 30/13⟩."
  },
  "examples": [
    {
      "given": {
        "a": [
          3,
          5,
          1
        ],
        "b": [
          -1,
          4,
          3
        ]
      },
      "expect": {
        "projection": "⟨−10/13, 40/13, 30/13⟩",
        "decimal": "⟨−0.769231, 3.07692, 2.30769⟩",
        "orthogonal": "⟨49/13, 25/13, −17/13⟩",
        "factor": "10/13",
        "dot": 20,
        "scalar": 3.922322702763681,
        "angle": 48.47142092270009
      },
      "source": "OpenStax, Calculus Volume 3, §2.3 The Dot Product (proj_u v = (u · v ÷ ‖u‖²) u, comp_u v = u · v ÷ ‖u‖; Example 2.27: the projection of ⟨3, 5, 1⟩ onto ⟨−1, 4, 3⟩ is ⟨−10/13, 40/13, 30/13⟩), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02); hand calculation in content.mdx: a · b = 20, ‖b‖² = 26; Python 3: 20/math.sqrt(26); the angle within 1e-12 because degrees may differ from Python in the last digit",
      "tolerance": 1e-12
    },
    {
      "given": {
        "a": [
          4,
          3
        ],
        "b": [
          1,
          0
        ]
      },
      "expect": {
        "projection": "⟨4, 0⟩",
        "orthogonal": "⟨0, 3⟩",
        "scalar": 4,
        "angle": 36.86989764584401
      },
      "source": "hand calculation in content.mdx: onto the x axis the projection keeps the x component; OpenStax, Calculus Volume 3, §2.3 The Dot Product (proj_u v = (u · v ÷ ‖u‖²) u, comp_u v = u · v ÷ ‖u‖; Example 2.27: the projection of ⟨3, 5, 1⟩ onto ⟨−1, 4, 3⟩ is ⟨−10/13, 40/13, 30/13⟩), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02); Python 3: math.degrees(math.acos(0.8)) (angle within 1e-12, last digit)",
      "tolerance": 1e-12
    },
    {
      "given": {
        "a": [
          1,
          2
        ],
        "b": [
          -2,
          1
        ]
      },
      "expect": {
        "projection": "⟨0, 0⟩",
        "orthogonal": "⟨1, 2⟩",
        "dot": 0,
        "scalar": 0,
        "angle": 90
      },
      "source": "hand calculation in content.mdx: a · b = −2 + 2 = 0, so a is orthogonal to b; OpenStax, Calculus Volume 3, §2.3 The Dot Product (proj_u v = (u · v ÷ ‖u‖²) u, comp_u v = u · v ÷ ‖u‖; Example 2.27: the projection of ⟨3, 5, 1⟩ onto ⟨−1, 4, 3⟩ is ⟨−10/13, 40/13, 30/13⟩), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02)"
    },
    {
      "given": {
        "a": [
          0.5,
          1.5
        ],
        "b": [
          1,
          1
        ]
      },
      "expect": {
        "projection": "⟨1, 1⟩",
        "factor": "1",
        "scalar": 1.414213562373095
      },
      "source": "hand calculation in content.mdx: a · b = 2, b · b = 2, so the projection is b; OpenStax, Calculus Volume 3, §2.3 The Dot Product (proj_u v = (u · v ÷ ‖u‖²) u, comp_u v = u · v ÷ ‖u‖; Example 2.27: the projection of ⟨3, 5, 1⟩ onto ⟨−1, 4, 3⟩ is ⟨−10/13, 40/13, 30/13⟩), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02)"
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 3, §2.3 The Dot Product (proj_u v = (u · v ÷ ‖u‖²) u, comp_u v = u · v ÷ ‖u‖; Example 2.27: the projection of ⟨3, 5, 1⟩ onto ⟨−1, 4, 3⟩ is ⟨−10/13, 40/13, 30/13⟩). https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02)"
  ],
  "related": [
    "dot-product",
    "magnitude",
    "gram-schmidt",
    "cross-product"
  ],
  "changelog": []
}
