-
Notifications
You must be signed in to change notification settings - Fork 1
/
point2.cpp
executable file
·59 lines (51 loc) · 1.18 KB
/
point2.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
58
#include "point2.h"
Point2::Point2(){
this->x = 0;
this->y = 0;
}
Point2::Point2(float x, float y){
this->x = x;
this->y = y;
}
Point2 Point2::operator+(const Point2& other){
Point2 result(this->x + other.x, this->y + other.y);
return result;
}
Point2 Point2::operator-(const Point2& other){
Point2 result(this->x - other.x, this->y - other.y);
return result;
}
Point2 Point2::operator*(const Point2& other){
Point2 result(this->x * other.x, this->y * other.y);
return result;
}
Point2 Point2::operator/(const Point2& other){
Point2 result(this->x / other.x, this->y / other.y);
return result;
}
void Point2::operator=(const Point2& other){
this->x = other.x;
this->y = other.y;
}
void Point2::Transform(Point2 centroid, float scale, float rotation){
float xnew;
float ynew;
float PI = 3.14159265;
float rad = rotation * PI / 180.0f;
this->x -= centroid.x;
this->y -= centroid.y;
//scale
if(scale != 1){
this->x *= scale;
this->y *= scale;
}
//rotate
if(rotation != 0){
xnew = (this->x * cos(rad)) - (this->y * sin(rad));
ynew = (this->x * sin(rad)) + (this->y * cos(rad));
this->x = xnew;
this->y = ynew;
}
this->x += centroid.x;
this->y += centroid.y;
}