#ifndef _VECTOR_H #define _VECTOR_H #include #include "point.h" // Implements a vector in 2D class vector { public: // Normal constructors vector(double magnitude, double direction) { _magnitude = magnitude; _direction = direction; } vector(const point& source, const point& dest); vector(); // Copy constructor vector(const vector&); // Accessors, sorta double componentX() const { return (_magnitude * cos(_direction)); }; double componentY() const { return (_magnitude * sin(_direction)); }; // Sets individual components // Wrappers around setComponents(double, double) - below void setComponentX(double x); void setComponentY(double y); // Sets both components at once void setComponents(double x, double y); // Accessors double magnitude() const { return _magnitude; } double direction() const { return _direction; } void setMagnitude(double m) { _magnitude = m; } void setDirection(double d) { _direction = d; } // Vector math vector operator+(const vector&); vector operator-(const vector&); vector& operator+=(const vector&); vector& operator-=(const vector&); // Dot product double operator*(const vector&); // Magnitude math vector operator+(double m) { return vector(_magnitude + m, _direction); } vector operator-(double m) { return vector(_magnitude - m, _direction); } vector operator*(double m) { return vector(_magnitude * m, _direction); } vector operator/(double m) { return vector(_magnitude / m, _direction); } vector& operator+=(double m); vector& operator-=(double m); vector& operator*=(double m); vector& operator/=(double m); // Return the vector's equalivent on the unit circle vector unit() const { return vector(1.0, _direction); } protected: double _magnitude; double _direction; }; #endif