{
  "id": "vector",
  "version": "a2d4ccb03938",
  "status": "published",
  "name": "Vector Calculator",
  "question": "What do my vectors add up to?",
  "summary": "Adds, subtracts and scales 2D or 3D vectors, and finds their lengths, dot product, the angle between them, the unit vector and the cross product.",
  "category": "math",
  "subcategory": "linear-algebra",
  "url": "https://www.acalculator.org/math/vector-calculator",
  "markdown": "https://www.acalculator.org/math/vector-calculator.md",
  "kind": "function",
  "method": "A ± B = ⟨a₁ ± b₁, a₂ ± b₂, a₃ ± b₃⟩; k·A = ⟨ka₁, ka₂, ka₃⟩; |A| = √(a₁² + a₂² + a₃²); A · B = a₁b₁ + a₂b₂ + a₃b₃; cos θ = A · B ÷ (|A| |B|); A × B = ⟨a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁⟩.",
  "assumptions": [
    "The vectors have real components in the usual x, y (and z) directions; 2D vectors leave out z.",
    "There is no angle and no unit vector for a zero vector, which has no direction."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "dim": {
        "title": "Vectors in",
        "description": "Whether the vectors have two components (x, y) or three (x, y, z).",
        "type": "string",
        "enum": [
          "2d",
          "3d"
        ]
      },
      "ax": {
        "title": "A: x",
        "description": "The x component of vector A.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "ay": {
        "title": "A: y",
        "description": "The y component of vector A.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "az": {
        "title": "A: z",
        "description": "The z component of vector A.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "bx": {
        "title": "B: x",
        "description": "The x component of vector B.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "by": {
        "title": "B: y",
        "description": "The y component of vector B.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "bz": {
        "title": "B: z",
        "description": "The z component of vector B.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "k": {
        "title": "Scalar k",
        "description": "A number to multiply vector A by.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      }
    }
  },
  "outputs": {
    "sum": {
      "label": "A + B",
      "description": "The sum, component by component.",
      "format": "text"
    },
    "difference": {
      "label": "A − B",
      "description": "The difference, component by component.",
      "format": "text"
    },
    "scaled": {
      "label": "k·A",
      "description": "Vector A with each component multiplied by k.",
      "format": "text"
    },
    "lengthA": {
      "label": "|A|",
      "description": "The length (magnitude) of A: the square root of the sum of its squared components.",
      "format": "number"
    },
    "lengthB": {
      "label": "|B|",
      "description": "The length (magnitude) of B.",
      "format": "number"
    },
    "dot": {
      "label": "A · B",
      "description": "The dot product: the sum of the products of matching components.",
      "format": "number"
    },
    "angle": {
      "label": "Angle between A and B (°)",
      "description": "The angle θ with cos θ = A · B ÷ (|A| |B|), in degrees.",
      "format": "number"
    },
    "unitA": {
      "label": "Unit vector of A",
      "description": "A divided by its length: the vector of length 1 in the direction of A.",
      "format": "text"
    },
    "cross": {
      "label": "A × B",
      "description": "The cross product (3D only): a vector at right angles to both A and B.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "dim": "3d",
      "ax": 3,
      "ay": 5,
      "az": 2,
      "bx": -1,
      "by": 3,
      "bz": 0,
      "k": 2
    },
    "outputs": {
      "sum": "⟨2, 8, 2⟩",
      "difference": "⟨4, 2, 2⟩",
      "scaled": "⟨6, 10, 4⟩",
      "lengthA": 6.164414002968976,
      "lengthB": 3.1622776601683795,
      "dot": 12,
      "angle": 52.00541403743851,
      "unitA": "⟨0.4866642634, 0.8111071057, 0.3244428423⟩",
      "cross": "⟨-6, -2, 14⟩"
    },
    "text": "A + B = ⟨2, 8, 2⟩, and A · B = 12."
  },
  "examples": [
    {
      "given": {
        "dim": "3d",
        "ax": 3,
        "ay": 5,
        "az": 2,
        "bx": -1,
        "by": 3,
        "bz": 0,
        "k": 2
      },
      "expect": {
        "dot": 12,
        "sum": "⟨2, 8, 2⟩",
        "difference": "⟨4, 2, 2⟩",
        "scaled": "⟨6, 10, 4⟩",
        "cross": "⟨-6, -2, 14⟩",
        "lengthA": 6.164414002968976,
        "lengthB": 3.1622776601683795
      },
      "source": "OpenStax, Calculus Volume 3, §2.3 The Dot Product (Example 2.21: u · v = 12), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product; hand calculation in content.mdx for the sum, difference, k·A and cross product (§2.4, https://openstax.org/books/calculus-volume-3/pages/2-4-the-cross-product)"
    },
    {
      "given": {
        "dim": "3d",
        "ax": 2,
        "ay": 5,
        "az": 6,
        "bx": -2,
        "by": -4,
        "bz": 4,
        "k": 1
      },
      "expect": {
        "dot": 0,
        "angle": 90
      },
      "source": "OpenStax, Calculus Volume 3, §2.3 The Dot Product (Example 2.23: cos θ = 0, θ = 90°), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product"
    },
    {
      "given": {
        "dim": "2d",
        "ax": 1,
        "ay": 2,
        "bx": 3,
        "by": 4,
        "k": -1
      },
      "expect": {
        "lengthA": 2.23606797749979,
        "unitA": "⟨0.4472135955, 0.894427191⟩",
        "sum": "⟨4, 6⟩",
        "scaled": "⟨-1, -2⟩",
        "dot": 11,
        "lengthB": 5,
        "angle": 10.304846468766044
      },
      "source": "OpenStax, Calculus Volume 3, §2.1 Vectors in the Plane (Example 2.7), https://openstax.org/books/calculus-volume-3/pages/2-1-vectors-in-the-plane; hand calculation in content.mdx for the angle: cos θ = 11 ÷ (5√5), θ = 10.3048°",
      "tolerance": 1e-12
    },
    {
      "given": {
        "dim": "2d",
        "ax": 0.1,
        "ay": 0.2,
        "bx": 0.2,
        "by": 0.1,
        "k": 3
      },
      "expect": {
        "sum": "⟨0.3, 0.3⟩",
        "dot": 0.04,
        "scaled": "⟨0.3, 0.6⟩"
      },
      "source": "hand calculation in content.mdx: 0.1 + 0.2 = 0.3, 0.02 + 0.02 = 0.04; OpenStax, Calculus Volume 3, §2.1 Vectors in the Plane, https://openstax.org/books/calculus-volume-3/pages/2-1-vectors-in-the-plane"
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 3, §2.1 Vectors in the Plane: vector sum, scalar multiple, magnitude, unit vectors (Example 2.7). https://openstax.org/books/calculus-volume-3/pages/2-1-vectors-in-the-plane (retrieved 2026-10-02)",
    "OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions. https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions (retrieved 2026-10-02)",
    "OpenStax, Calculus Volume 3, §2.3 The Dot Product: u · v and the angle between vectors (Examples 2.21 and 2.23). https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product (retrieved 2026-10-02)",
    "OpenStax, Calculus Volume 3, §2.4 The Cross Product. https://openstax.org/books/calculus-volume-3/pages/2-4-the-cross-product (retrieved 2026-10-02)"
  ],
  "related": [
    "dot-product",
    "cross-product",
    "distance-formula",
    "polar-coordinates"
  ],
  "changelog": []
}
