Point class
 
Betöltés...
Keresés...
Nincs egyezés
point.cpp
Ugrás a fájl dokumentációjához.
1#define _USE_MATH_DEFINES
2#include "point.h"
3#include <cmath>
4
5
6namespace bme {
7
9 x = .0;
10 y = .0;
11 }
12
13 Point::Point(double xx, double yy) {
14 x = xx;
15 y = yy;
16 }
17
18 double Point::getX()const {
19 return x;
20 }
21
22 double Point::getY()const {
23 return y;
24 }
25
26 void Point::setX(double xx) {
27 x = xx;
28 }
29
30 void Point::setY(double yy) {
31 y = yy;
32 }
33
34 double Point::getR()const {
35 return sqrt(x*x+y*y);
36 }
37
38 void Point::setR(double r) {
39 //ha a pont az origó, akkor beállítjuk az (r,0) pontot
40 if ((x == 0.) && (y == 0.)) {
41 x = r;
42 return;
43 }
44
45 //különben beállítjuk a pontot (r*cos(A),r*sin(A))-ra,
46 //ahol A a pontba mutató vektor és az x tengely által bezárt szög
47 double A = getA();
48 x = r * cos(A);
49 y = r * sin(A);
50 }
51
52 double Point::getA()const {
53 if ((x == 0.) && (y == 0.)) {
54 return .0;
55 }
56
57 double A = atan2(y, x);
58 if (A < 0) {
59 A += 2 * M_PI;
60 }
61
62 return A;
63 }
64
65 void Point::setA(double theta) {
66 double r = getR();
67 x = r * cos(theta);
68 y = r * sin(theta);
69 }
70
71 void Point::rotate(double theta) {
72 double A = getA();
73 A += theta;
74 setA(A);
75 }
76
77 bool Point::operator==(const Point& Q)const {
78 return ((x == Q.x) && (y == Q.y));
79 }
80
81 bool Point::operator!=(const Point& Q)const {
82 return !((*this) == Q);
83 }
84
86 x = Q.x;
87 y = Q.y;
88 return *this;
89 }
90
91 Point Point::operator+(const Point& Q) const{
92 return Point(x + Q.x, y + Q.y);
93 }
94
95 Point Point::operator-(const Point& Q) const {
96 return Point(x - Q.x, y - Q.y);
97 }
98
99 Point Point::operator*(double c) const {
100 return Point(c*x, c*y);
101 }
102
103 Point Point::operator/(double c) const {
104 return Point(x/c, y/c);
105 }
106
107
109 return (*this) = (*this) + Q;
110 }
111
113 return (*this) = (*this) - Q;
114 }
115
117 return (*this) = (*this) * c;
118 }
119
121 return (*this) = (*this) / c;
122 }
123
124 double dist(Point P, Point Q) {
125 double dx = P.getX() - Q.getX();
126 double dy = P.getY() - Q.getY();
127 return sqrt(dx * dx + dy * dy);
128 }
129
131 return (P+Q)/2.;
132 }
133
134 ostream& operator<<(ostream& os, const Point& P) {
135 os << "(" << P.getX() << "," << P.getY() << ")";
136 return os;
137 }
138
139 Point operator*(double c, const Point& P) {
140 return P*c;
141 }
142}
void rotate(double theta)
a pont forgatása az origó körül
Definition point.cpp:71
double getX() const
a pont első (x) koordinátája
Definition point.cpp:18
Point & operator-=(const Point &Q)
Definition point.cpp:112
Point & operator*=(double c)
Definition point.cpp:116
Point operator*(double c) const
pont skalárral való szorzása
Definition point.cpp:99
void setX(double xx)
x koordináta beállítása
Definition point.cpp:26
Point & operator/=(double c)
Definition point.cpp:120
Point()
Default konstruktor.
Definition point.cpp:8
Point & operator=(const Point &Q)
Definition point.cpp:85
Point operator+(const Point &Q) const
pontok mint vektorok összeadása
Definition point.cpp:91
double getY() const
a pont második (y) koordinátája
Definition point.cpp:22
bool operator==(const Point &Q) const
Definition point.cpp:77
void setA(double theta)
a pontba mutató vektor szögének beállítása
Definition point.cpp:65
void setY(double yy)
y koordináta beállítása
Definition point.cpp:30
void setR(double r)
a pontba mutató vektor skálázása
Definition point.cpp:38
double getR() const
a pontba mutató vektor hossza
Definition point.cpp:34
Point & operator+=(const Point &Q)
Definition point.cpp:108
Point operator-(const Point &Q) const
pontok mint vektorok kivonása
Definition point.cpp:95
bool operator!=(const Point &Q) const
Definition point.cpp:81
double getA() const
a pontba mutató vektor szöge
Definition point.cpp:52
Point operator/(double c) const
pont skalárral való osztása (reciprokkal való szorzás)
Definition point.cpp:103
Definition point.cpp:6
Point operator*(double c, const Point &P)
skalárral való szorzás
Definition point.cpp:139
double dist(Point P, Point Q)
két pont távolsága
Definition point.cpp:124
Point midpoint(Point P, Point Q)
felezőpont
Definition point.cpp:130
ostream & operator<<(ostream &os, const Point &P)
pont kiírása
Definition point.cpp:134
a Point osztály és kapcsolódó függvények deklarációja