class Vector { public: float x, y, z; Vector(float x1 = 0, float y1 = 0, float z1 = 0) { x = x1; y = y1; z = z1; }; float mag(); }; Vector operator+(Vector v1, Vector v2) { return Vector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); } Vector operator-(Vector v1, Vector v2) { return Vector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); } Vector operator*(Vector v1, float f) { return Vector(v1.x * f, v1.y * f, v1.z * f); } Vector operator*(float f, Vector v1) { return Vector(v1.x * f, v1.y * f, v1.z * f); } Vector operator*(Vector v1, Vector v2) { return Vector(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); } Vector operator/(Vector v1, float f) { return Vector(v1.x / f, v1.y / f, v1.z / f); } Vector sign(Vector v) { return Vector(v.x / abs(v.x), v.y / abs(v.y), v.z / abs(v.z)); } Vector abs(Vector v) { return Vector(fabs(v.x), fabs(v.y), fabs(v.z)); } float dot(Vector v1, Vector v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } float Vector::mag() { return x * x + y * y + z * z; }