Point Oop CPP
Point Oop CPP
h"
2
3 #include <cmath>
4
5 #include "geo_compare.h"
6
7 /*Point::Point(double xIn, double yIn)
8 {
9 x = xIn;
10 y = yIn;
11 }*/
12
13 Point::Point(double distance, Angle angle)
14 {
15 x = distance * cos(angle.getValueBetweenMinusPiAndPi());
16 y = distance * sin(angle.getValueBetweenMinusPiAndPi());
17 }
18
19 bool Point::operator==(Point point2)
20 {
21 geo_compare compare;
22 return compare.isFuzzyEqual(*this, point2, 0.00001);
23 }
24
25 double Point::getLength()
26 {
27 return sqrt(x * x + y * y);
28 }
29
30 double Point::distanceTo(Point two)
31 {
32 Point pointTemp = Point{x - two.x, y - two.y}; //!!
33 return pointTemp.getLength();
34 }
35
36 Point Point::operator-(Point two)
37 {
38 return Point(x - two.x, y - two.y); // å¯ä»¥å å»Pointç¨å¤§æ¬å·ä»£æ¿
39 }
40
41 Point Point::operator+(Point two)
42 {
43 return Point(x + two.x, y + two.y);
44 }
45
46 Point Point::operator*(double factor)
47 {
48 return Point(x * factor, y * factor);
49 }
50
51 void Point::rotate(Angle angle)
52 {
53 double angleValue = angle.getValueBetweenMinusPiAndPi();
54 double xVal = x * cos(angleValue) - y * sin(angleValue);
55 double yVal = x * sin(angleValue) + y * cos(angleValue);
56 x = xVal;
57 y = yVal;
58 }
59
60 double Point::getX()
61 {
62 return x;
63 }
64
65 double Point::getY()
66 {
67 return y;
68 }