#include /* * Vec3: * A class to represent a 3D VECTOR * (maybe also a 3D point and 3D versor? we'll see) */ struct Vec3{ // fields (the 3 coordinates) double x; double y; double z; Vec3(double _x, double _y, double _z): x(_x), y(_y), z(_z){} Vec3():x(0), y(0), z(0) {} // by default, we use the degenerate vector (all zeros) /* vector algebra: scaling */ // in-place (method) void scale(double k){ x *= k; y *= k; z *= k; } // in-place (operator) void operator *=(double k){ x *= k; y *= k; z *= k; } // out of place (method) Vec3 scaled(double k) const{ return Vec3(x*k, y*k, z*k); } // out of place (operator) Vec3 operator *(double k) const{ return Vec3(x*k, y*k, z*k); } /* vector algebra: vector sum */ // out-of-place (method) Vec3 added(const Vec3 &b) const{ return Vec3(x + b.x, y+ b.y, z + b.z ); } // out-of-place (operator) Vec3 operator +(const Vec3 &b) const{ return Vec3(x + b.x, y+ b.y, z + b.z ); } // in-place (method) void add(const Vec3 &b) { x += b.x; y += b.y; z += b.z; } // in-place (operator) void operator += (const Vec3 &b) { x += b.x; y += b.y; z += b.z; } void debug_print() const{ std::cout<<"X:" << x << " Y:" << y << " Z:" <