/********************************************************************
Engineering 3891 Advanced Structured Programming
Assignment: 6 Date Due: November 16th/2000
Name: Daryl Martin
Student #: 9713520
Username: darylm
*********************************************************************/
#include "assign6.h"
#include <cmath>
/******************************************************************
* Vector::Vector -- A copy constructor
*
* Parameters:
* x -- The horizontal componet of a vector
* y -- The vertical componet of a vector
*
* Modifies: none
*
* Date: 11/17/00
*******************************************************************/
Vector::Vector(double x, double y)
{
loc.x = x;
loc.y = y;
}
/******************************************************************
* Vector::get() -- This program returns the current location
* of a vector
*
* Parameters:
* loc -- The location of the vector
*
* Modifies: none
*
* Returns: The location of the vector Date: 11/17/00
*******************************************************************/
point Vector::get() const
{
return loc;
}
/******************************************************************
* Vector::scale -- Scales the vector by a constant of type double
*
* Parameters:
* s -- The factor you want to scale the vector by
*
* Modifies: none
*
* Date: 11/17/00
*******************************************************************/
void Vector::scale(double s)
{
loc.x = loc.x*s;
loc.y = loc.y*s;
}
/******************************************************************
* Vector::rot -- Rotates the vector by an angle which is given
* by the user.
*
* Parameters:
* a -- The angle you want to rotate the vector by
*
* Modifies: none
*
* Returns: True or false Date: 11/17/00
*******************************************************************/
void Vector::rot(double a)
{
a *= acos(-1) / 180;
point tempVector;
tempVector.x = loc.x * cos(a) - loc.y * sin(a);
tempVector.y = loc.y * cos(a) + loc.x * sin(a);
loc = tempVector;
}
/******************************************************************
* Vector::reflect -- Flip definitions. NOTE - a horizontal flip
* means in the horizontal plane (therefore
* ABOUT the vertical axis). And vice versa.
*
* Parameters:
* f -- the axis you want to rotate about.
*
* Modifies: none
*
* Date: 11/17/00
*******************************************************************/
void Vector::reflect(flip f)
{
switch (f)
{
case 0: //Vector Doesn't move
break;
case 1: //Vector flip about the vertical
loc.x = -loc.x;
break;
case 2: //Vector flip about the horizontal
loc.y = -loc.y;
break;
case 3: //Vector flips about both axis
loc.x = -loc.x;
loc.y = -loc.y;
break;
default:
break;
}
}
/******************************************************************
* Vector::add -- Adds two vectors together
*
* Parameters:
* v -- the vector you want to be added to the vector
*
* Modifies: none
*
* Date: 11/17/00
*******************************************************************/
void Vector::add(const Vector& v)
{
loc.x = loc.x + v.loc.x;
loc.y = loc.y + v.loc.y;
}
/******************************************************************
* Vector::subtract -- subtracts a vector from the vector
*
* Parameters:
* v -- The vector you want to subtract from the vector
*
* Modifies: none
*
* Date: 11/17/00
*******************************************************************/
void Vector::subtract(const Vector& v)
{
loc.x = loc.x - v.loc.x;
loc.y = loc.y - v.loc.y;
}