Vector Calculator
Calculate 2D and 3D vector addition, subtraction, dot product, cross product, and magnitude.
About this tool
A vector is a mathematical quantity with both magnitude and direction, and vector operations form the foundation of physics, engineering, graphics programming, and machine learning. This calculator helps you perform core vector calculations including addition, subtraction, dot product, cross product, and magnitude—all the essential operations needed to work with vectors in 2D and 3D space.
Simply enter the components of your vectors and select the operation you need. The calculator instantly shows the result, making it easy to verify vector algebra homework, check calculations for physics problems, or explore how vectors work in computer graphics and game development. All computations run locally in your browser, so your data stays on your device.
Frequently Asked Questions
Code Implementation
import math
# 3D Vector operations
class Vector3:
def __init__(self, x, y, z=0):
self.x, self.y, self.z = x, y, z
def __add__(self, v): return Vector3(self.x+v.x, self.y+v.y, self.z+v.z)
def __sub__(self, v): return Vector3(self.x-v.x, self.y-v.y, self.z-v.z)
def __mul__(self, s): return Vector3(self.x*s, self.y*s, self.z*s)
def magnitude(self):
return math.sqrt(self.x**2 + self.y**2 + self.z**2)
def normalize(self):
m = self.magnitude()
return Vector3(self.x/m, self.y/m, self.z/m)
def dot(self, v):
return self.x*v.x + self.y*v.y + self.z*v.z
def cross(self, v):
return Vector3(
self.y*v.z - self.z*v.y,
self.z*v.x - self.x*v.z,
self.x*v.y - self.y*v.x
)
def angle_with(self, v):
cos_a = self.dot(v) / (self.magnitude() * v.magnitude())
return math.degrees(math.acos(max(-1, min(1, cos_a))))
def __repr__(self): return f"({self.x}, {self.y}, {self.z})"
# Examples
a = Vector3(1, 2, 3)
b = Vector3(4, 5, 6)
print(f"A + B = {a + b}") # (5, 7, 9)
print(f"|A| = {a.magnitude():.4f}") # 3.7417
print(f"A · B = {a.dot(b)}") # 32
print(f"A × B = {a.cross(b)}") # (-3, 6, -3)
print(f"Angle = {a.angle_with(b):.2f}°") # 12.93°
print(f"norm(A) = {a.normalize()}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.