def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
class Vector3D:
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def magnitude(self):
return (self.x**2 + self.y**2 + self.z**2)**0.5
def normalize(self):
mag = self.magnitude()
if mag == 0:
return Vector3D(0, 0, 0)
return Vector3D(self.x/mag, self.y/mag, self.z/mag)
def dot(self, other):
return self.x * other.x + self.y * other.y + self.z * other.z
def cross(self, other):
return Vector3D(
self.y * other.z - self.z * other.y,
self.z * other.x - self.x * other.z,
self.x * other.y - self.y * other.x
)