-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint2D.cpp
47 lines (44 loc) · 816 Bytes
/
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
#include "Point2D.h"
#include <cmath>
#include <iostream>
#include "Vector2D.h"
using namespace std;
Point2D :: Point2D()
{
x=0.0;
y=0.0;
}
Point2D :: Point2D(double in_x, double in_y)
{
x=in_x;
y=in_y;
}
//do we need to include Point2D :: every time??
double GetDistanceBetween(Point2D p1, Point2D p2)
{
double distance;
distance=sqrt(pow((p2.y - p1.y),2) + pow((p2.x - p1.x),2));
return distance;
}
//stream output operator
ostream& operator <<(ostream& out, Point2D p)
{
out<<"("<<p.x<<","<<p.y<<")";
return out;
}
//addition operator
Point2D operator +(Point2D p1, Vector2D v1)
{
Point2D newp;
newp.x=p1.x+v1.x;
newp.y=p1.y+v1.y;
return newp;
}
//substraction operator
Vector2D operator -(Point2D p1, Point2D p2)
{
Vector2D newv;
newv.x=p1.x-p2.x;
newv.y=p1.y-p2.y;
return newv;
}