Added Subtract method to Vector

feature/19
Daniel Warner 2011-04-09 20:01:19 +01:00
parent 6824a51d70
commit c2a7fbe2e1
2 changed files with 21 additions and 1 deletions

View File

@ -3,3 +3,14 @@
double Vector::GetMagnitude() const { double Vector::GetMagnitude() const {
return sqrt(x_ * x_ + y_ * y_ + z_ * z_); return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
} }
/*
* subtract (this) - (v)
* and return result
*/
Vector Vector::Subtract(const Vector& vec) const {
return Vector(x_ - vec.x_,
y_ - vec.y_,
z_ - vec.z_,
0.0);
}

View File

@ -6,7 +6,15 @@
class Vector { class Vector {
public: public:
Vector(double x = 0.0, double y = 0.0, double z = 0.0, double w = 0.0) Vector(void)
: x_(0.0), y_(0.0), z_(0.0), w_(0.0) {
}
Vector(double x, double y, double z)
: x_(x), y_(y), z_(z), w_(0.0) {
}
Vector(double x, double y, double z, double w)
: x_(x), y_(y), z_(z), w_(w) { : x_(x), y_(y), z_(z), w_(w) {
} }
@ -46,6 +54,7 @@ public:
} }
double GetMagnitude() const; double GetMagnitude() const;
Vector Subtract(const Vector& v) const;
protected: protected:
double x_; double x_;