/***************************************************************************************
***** CLASS POINT IMPLEMENTATION *****
****************************************************************************************
** Author: Peter Stuart
** Email: chester@selway.umt.edu
** Date: 3/7/98
** Description: This class implements a point in 3-space. Operations include all the
** necessary conversions from points to vectors, along with basic operators
**
** NOTE: The matrices, vectors, and points use homogeneous coordinates
**
***************************************************************************************/
#include "Point.hpp"
/* Constructor **********
** Default values for priavte variables:
** _x = 0.0
** _y = 0.0
** _z = 0.0
*/
Point::Point(const double x, const double y, const double z)
{
_x = x;
_y = y;
_z = z;
}
// Copy Constructor
Point::Point(const Point& pt)
{
_x = pt._x;
_y = pt._y;
_z = pt._z;
}
// Destructor
Point::~Point()
{
;
}
// ELEMENTARY OPERATORS //////////////////
// Assignment operator
Point& Point::operator = (const Point& pt)
{
if (this == &pt)
return (*this);
_x = pt._x;
_y = pt._y;
_z = pt._z;
return (*this);
}
// addition of vector to point
Point operator + (const Point& pt, const Vector& v)
{
Point temp; // returning point
temp._x = pt._x + v.x();
temp._y = pt._y + v.y();
temp._z = pt._z + v.z();
return temp;
}
Point operator + (const Vector& v, const Point& pt)
{
Point temp; // returning point
temp._x = pt._x + v.x();
temp._y = pt._y + v.y();
temp._z = pt._z + v.z();
return temp;
}
// negative point
Point operator - (const Point& pt)
{
Point temp; // returning point
temp._x = -pt._x;
temp._y = -pt._y;
temp._z = -pt._z;
return temp;
}
// two points to vector
Vector operator - (const Point& pt1, const Point& pt2)
{
double tempx, tempy, tempz;
tempx = pt1._x - pt2._x;
tempy = pt1._y - pt2._y;
tempz = pt1._z - pt2._z;
Vector tempV(tempx, tempy, tempz); // returning vector
return tempV;
}
// subtraction of vector from point
Point operator - (const Point& pt, const Vector& v)
{
Point temp; // returning point
temp._x = pt._x - v.x();
temp._y = pt._y - v.y();
temp._z = pt._z - v.z();
return temp;
}
// scalar multiplication of point
Point operator * (const Point& pt, const double val)
{
Point temp; // returning point
temp._x = pt._x * val;
temp._y = pt._y * val;
temp._z = pt._z * val;
return temp;
}
Point operator * (const double val, const Point& pt)
{
Point temp; // returning point
temp._x = pt._x * val;
temp._y = pt._y * val;
temp._z = pt._z * val;
return temp;
}
Point operator / (const Point& pt, const double val)
{
Point temp; // returning point
temp._x = pt._x / val;
temp._y = pt._y / val;
temp._z = pt._z / val;
return temp;
}
Point operator / (const double val, const Point& pt)
{
Point temp; // returning point
temp._x = pt._x / val;
temp._y = pt._y / val;
temp._z = pt._z / val;
return temp;
}
// Relational operators
int operator == (const Point& pt1, const Point& pt2)
{
if (pt1._x != pt2._x)
return FALSE;
if (pt1._y != pt2._y)
return FALSE;
if (pt1._z != pt2._z)
return FALSE;
return TRUE;
}
int operator != (const Point& pt1, const Point& pt2)
{
if (pt1._x == pt2._x)
return FALSE;
if (pt1._y == pt2._y)
return FALSE;
if (pt1._z == pt2._z)
return FALSE;
return TRUE;
}
// output stream
ostream& operator << (ostream& co, const Point& pt)
{
co << "<" << pt._x << ", " << pt._y << ", " << pt._z << ">";
return co;
}
               (
geocities.com/collegepark)