Alex Allen / vectr

vectr.h

Committer:
AlexAllen
Date:
2012-10-13
Revision:
0:55dbdc9614f8

File content as of revision 0:55dbdc9614f8:

/* Copyright (c) 2011 Alex Allen, MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #ifndef VECTR

#include <iostream>
using namespace std;

class vectr
{
    double x,y,z;
    
    public:
    
    vectr(); // initialises vector as all 0s
    vectr(double num); // initialises vector as all num
    vectr(double a, double b); // x = a, y = b, z = 0
    vectr(double a, double b, double c); // x = a, y = b, z = c
    
    void set(double a, double b, double c); // sets all values of the vector
    void setx(double a);  // sets the x component
    void sety(double b); // sets the y component
    void setz(double c);  // sets the z component
    
    double getx(); // gets the x component
    double gety(); // gets the y component
    double getz(); // gets the z component
    
    double mag(); // returns magnitude of the vector
    double mag2(); // returns magnitude squared of the vector

    vectr unit(); // returns the unit vector
    vectr operator+(vectr ob2); // output = this + ob2
    vectr operator-(vectr ob2); // output = this - ob2
    double operator*(vectr ob2); // output = dot product of this and ob2
    vectr operator*(double num); // output = this * num
    
    friend vectr operator*(double num, vectr ob); // output = num * ob
    vectr operator%(vectr ob2); // output = cross product of this and ob2
    vectr operator/(double num); // output = this / num
    friend vectr operator/(double num, vectr ob); // output = num * 1/ob
    
    // output = dot product of this and 1/ob
    double operator/(vectr ob2);
    vectr operator+=(vectr ob2);
    vectr operator-=(vectr ob2);
    vectr operator*=(double num);
    vectr operator/=(double num);
    
    // output in the form "(x, y, z)"
    friend ostream &operator<<(ostream &stream, vectr ob);
};

#define VECTR 1
#endif