Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Created July 19, 2012 11:16
Show Gist options
  • Save JAChapmanII/3143124 to your computer and use it in GitHub Desktop.
Save JAChapmanII/3143124 to your computer and use it in GitHub Desktop.
simple vector thing
#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