Created
July 19, 2012 11:16
-
-
Save JAChapmanII/3143124 to your computer and use it in GitHub Desktop.
simple vector thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
class Vector { | |
public: | |
Vector() : x(0), y(0), z(0) { | |
} | |
Vector(double iX, double iY, double iZ) : x(iX), y(iY), z(iZ) { | |
} | |
double magnitude() const { | |
return sqrt(x*x + y*y + z*z); | |
} | |
Vector &operator=(const Vector &rhs) { | |
x = rhs.x; | |
y = rhs.y; | |
z = rhs.z; | |
return (*this); | |
} | |
Vector operator+(const Vector &rhs) { | |
return Vector(x + rhs.x, y + rhs.y, z + rhs.z); | |
} | |
Vector operator+=(const Vector &rhs) { | |
return (*this) = (*this) + rhs; | |
} | |
double x; | |
double y; | |
double z; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment