-
Notifications
You must be signed in to change notification settings - Fork 37
/
Point2D.cpp
124 lines (100 loc) · 2.49 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// Created by Neirokan on 09.05.2020
//
#include "Point2D.h"
#include <cmath>
Point2D Point2D::operator+(const Point2D& point2D) const
{
return Point2D{ this->x + point2D.x, this->y + point2D.y };
}
Point2D Point2D::operator-(const Point2D& point2D) const
{
return Point2D{ this->x - point2D.x, this->y - point2D.y };
}
Point2D Point2D::operator*(double number) const
{
return Point2D{ this->x * number, this->y * number };
}
Point2D Point2D::operator/(double number) const
{
return Point2D{ this->x * number, this->y * number };
}
Point2D& Point2D::operator= (const Point2D& point2D)
{
this->x = point2D.x;
this->y = point2D.y;
return *this;
}
Point2D& Point2D::operator+=(const Point2D& point2D)
{
this->x += point2D.x;
this->y += point2D.y;
return *this;
}
Point2D& Point2D::operator-=(const Point2D& point2D)
{
this->x -= point2D.x;
this->y -= point2D.y;
return *this;
}
Point2D& Point2D::operator*=(double number)
{
this->x *= number;
this->y *= number;
return *this;
}
Point2D& Point2D::operator/=(double number)
{
this->x /= number;
this->y /= number;
return *this;
}
bool Point2D::operator<(const Point2D& point2D) const {
return x < point2D.x && y < point2D.y;
}
bool Point2D::operator==(const Point2D& point2D)
{
return this == &point2D || (*this - point2D).sqrAbs() < 0.0000000001;
}
bool Point2D::operator!=(const Point2D& point2D)
{
return this != &point2D && (*this - point2D).sqrAbs() > 0.0000000001;
}
double Point2D::operator*(const Point2D& point2D) const
{
return this->x * point2D.x + this->y * point2D.y;
}
double Point2D::cross(const Point2D& point2D) const
{
return this->x * point2D.y - this->y * point2D.x;
}
double Point2D::dot(const Point2D& a, const Point2D& b)
{
return a.x * b.x + a.y * b.y;
}
double Point2D::cross(const Point2D& a, const Point2D& b)
{
return a.x * b.y - a.y * b.x;
}
Point2D Point2D::normalize() const
{
double length = this->abs();
return Point2D{ this->x / length, this->y / length };
}
double Point2D::sqrAbs() const
{
return x * x + y * y;
}
double Point2D::abs() const
{
return sqrt(x * x + y * y);
}
int signum(double n) {
return n >= 0 ? 1 : -1;
}
double Point2D::getAngle(const Point2D& b) const {
Point2D a = normalize();
Point2D d = b.normalize();
double result = asin(a.x*d.y - a.y*d.x);
return result;
}