-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint2D.cpp
58 lines (47 loc) · 1.04 KB
/
Point2D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <cmath>
#include <string.h>
#include "Point2D.h"
#include "Vector2D.h"
using namespace std;
//POINT2D.CPP
//represents a point on a Cartesian coordinate system
//default constructor
Point2D::Point2D()
{
x = 0.0;
y = 0.0;
}
//user-set constructor
Point2D::Point2D(double in_x, double in_y)
{
x = in_x;
y = in_y;
}
//non-member function returns Cartesian distance between p1 and p2
double GetDistanceBetween(Point2D p1, Point2D p2)
{
return sqrt(pow((p2.x - p1.x), 2) + pow((p2.y - p1.y), 2));
}
//non-member overloaded operator for <<
ostream& operator << (ostream& os, const Point2D& pt)
{
os << "(" << pt.x << ", " << pt.y << ")" << endl;
return os;
}
//non-member overloaded operator for +
Point2D operator + (Point2D pt1, Vector2D v1)
{
Point2D temp;
temp.x = (pt1.x + v1.x);
temp.y = (pt1.y + v1.y);
return temp;
}
//non-member overloaded operator for -
Vector2D operator - (Point2D pt1, Point2D pt2)
{
Vector2D temp;
temp.x = (pt1.x - pt2.x);
temp.y = (pt1.y - pt2.y);
return temp;
}