#include <iostream>
#include "math.h"
#include "point.h"
point::point(double xs, double ys) {
setPoint(xs, ys);
getPoint();
}
point::~point() {}
point::point &operator+(point p, point q) {
point r;
r.setPoint(p.getX()+q.getX(), p.getY()+q.getY());
return r;
}
point::point &operator-(point p, point q) {
point r;
r.setPoint(p.getX()-q.getX(), p.getY()-q.getY());
return r;
}
point::point &operator*(point p, point q) {
point r;
r.setPoint(p.getX()*q.getX(), p.getY()*q.getY());
return r;
}
point::point &operator/(point p, point q) {
point r;
r.setPoint(p.getX()/q.getX(), p.getY()/q.getY());
return r;
}
bool operator==(point p, point q) {
if(p.getX()==q.getX()) {
if(p.getY() == q.getY()) {
return true;
}
}
else {return false;}
}
bool operator!=(point p, point q) {
if(p.getX() != q.getX()) {
if(p.getY() != q.getY()) {
return true;
}
}
else return false;
}
point::void setX(double q) {x = q;}
point::void setY(double q) {y = q;}
point::void setR(double q) {r = q;}
point::void setTH(double q) {th = q;}
point::void distance(point p, point q) {
cout << sqrt((p.getX()-q.getX())^2+(p.getY()-q.getY())^2);
}
point::void midpoint(point p, point q) {
point r;
r.setPoint((p.getX()+q.getX())/2, (p.getY()+q.getY())/2);
cout << r;
}
point::void XY2Pol() {
double q; //for quadrant correction
r = sqrt(x^2+y^2);
if(x = 0) {
th = pi/2;
}
if((0 < x) && (0 < y)) {
q = 0;
}
else if((x < 0) && (0 < y)) {
q = -pi;
}
else if((x < 0) && (y > 0)) {
q = pi;
}
else if((0 < x) && (y < 0)) {
q = -2*pi;
}
double ath = arctan(abs(y/x));
th = abs(ath + q);
}
point::void Pol2XY() {
x = r*cos(th);
y = r*sin(th);
}
point::void rotate(double ph) {
XY2Pol();
double aph = -ph;
double ath = th;
ph = aph; //C++ calculates angles counter-clockwise
th = ath + ph;
Pol2XY(); //this function is cake with polar coords :)
}
|