#include "Vector.h" #include "Point3.h" #include #using Vector::Vector(void) { x = 0; y = 0; z = 0; } Vector::Vector(Point3* p1, Point3* p2) { x = p2->getX() - p1->getX(); y = p2->getY() - p1->getY(); z = p2->getZ() - p1->getZ(); } Vector::Vector(float x1, float y1, float z1) { x = x1; y = y1; z = z1; } Vector::Vector(float x1, float y1, float z1, float x2, float y2, float z2) { x = x2 - x1; y = y2 - y1; z = z2 - z1; } Vector::~Vector(void) { } float Vector::getX(void) { return x; } float Vector::getY(void) { return y; } float Vector::getZ(void) { return z; } void Vector::setX(float x1) { x = x1; } void Vector::setY(float y1) { y = y1; } void Vector::setZ(float z1) { z = z1; } float Vector::magnitude(void) { return sqrt(x*x + y*y + z*z); } void Vector::normalize(void) { float mag = this->magnitude(); if(mag != 0.f) { x = x / mag; y = y / mag; z = z / mag; } } Vector* Vector::normal(void) { float mag = this->magnitude(); if(mag != 0.f) { float x1 = x / mag; float y1 = y / mag; float z1 = z / mag; return new Vector(x1, y1, z1); } return this; } Vector* Vector::cross(Vector* v) { float x1 = ((this->y)*(v->z)) - ((this->z)*(v->y)); float y1 = ((this->z)*(v->x)) - ((this->x)*(v->z)); float z1 = ((this->x)*(v->y)) - ((this->y)*(v->x)); return new Vector(x1, y1, z1); }