Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Coordinate.h
- #ifndef CORDINATE_H
- #define CORDINATE_H
- #include <math.h>
- class Coordinate
- {
- public:
- Coordinate(void);
- Coordinate(int x, int y);
- Coordinate(int x, int y, int z);
- Coordinate(double x, double y);
- Coordinate(double x, double y, double z);
- Coordinate(Coordinate &c);
- ~Coordinate(void);
- Coordinate &operator=(Coordinate &c);
- bool operator==(Coordinate &c);
- double operator[](int i);
- double getX();
- double getY();
- double getZ();
- void setPos(int x, int y);
- void setPos(int x, int y, int z);
- void setPos(double x, double y);
- void setPos(double x, double y, double z);
- void deltaPos(int x, int y);
- void deltaPos(int x, int y, int z);
- void deltaPos(double x, double y);
- void deltaPos(double x, double y, double z);
- double inline distanceTo(Coordinate &c)
- {
- double dx = x - c.getX();
- double dy = y - c.getY();
- double dz = z - c.getZ();
- return sqrt(dx * dx + dy * dy + dz * dz);
- }
- protected:
- double x, y, z;
- private:
- double epsilon;
- };
- #endif
- Coordinate.cpp
- #include "Coordinate.h"
- #include <iostream>
- Coordinate::Coordinate(void)
- {
- x = y = z = 0;
- epsilon = 0.001
- }
- Coordinate::Coordinate(int x, int y)
- {
- this->x = x;
- this->y = y;
- this->z = 0;
- epsilon = 0.001
- }
- Coordinate::Coordinate(int x, int y, int z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- epsilon = 0.001
- }
- Coordinate::Coordinate(double x, double y)
- {
- this->x = x;
- this->y = y;
- this->z = 0;
- epsilon = 0.001
- }
- Coordinate::Coordinate(double x, double y, double z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- epsilon = 0.001
- }
- Coordinate::Coordinate(Coordinate &c)
- {
- this->setPos(c.getX(), c.getY());
- epsilon = 0.001
- }
- Coordinate::~Coordinate(void)
- {
- }
- Coordinate& Coordinate::operator=(Coordinate &c)
- {
- this->setPos(c.getX(), c.getY(), c.getZ());
- return *this;
- }
- bool Coordinate::operator==(Coordinate &c)
- {
- double dist = distanceTo(c);
- if(dist > epsilon)
- {
- return false;
- }
- else if(dist < epsilon)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- double Coordinate::operator[](int i)
- {
- if(i == 0)
- {
- return x;
- }
- else if(i == 1)
- {
- return y;
- }
- else if(i == 2)
- {
- return z;
- }
- else
- {
- std::cout << "Coordinate index is out of bounds" << std::endl;
- }
- }
- double Coordinate::getX()
- {
- return x;
- }
- double Coordinate::getY()
- {
- return y;
- }
- double Coordinate::getZ()
- {
- return z;
- }
- void Coordinate::setPos(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- void Coordinate::setPos(int x, int y, int z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- void Coordinate::setPos(double x, double y)
- {
- this->x = x;
- this->y = y;
- }
- void Coordinate::setPos(double x, double y, double z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- void Coordinate::deltaPos(int x, int y)
- {
- this->x = this->x + x;
- this->y = this->y + y;
- }
- void Coordinate::deltaPos(int x, int y, int z)
- {
- this->x = this->x + x;
- this->y = this->y + y;
- this->z = this->z + z;
- }
- void Coordinate::deltaPos(double x, double y)
- {
- this->x = this->x + x;
- this->y = this->y + y;
- }
- void Coordinate::deltaPos(double x, double y, double z)
- {
- this->x = this->x + x;
- this->y = this->y + y;
- this->z = this->z + z;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement