Created
July 14, 2020 14:20
Геометрия Вектор/точка
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Point { | |
double x; | |
double y; | |
Point(double x0 = 0, double y0 = 0) { | |
x = x0; | |
y = y0; | |
} | |
}; | |
struct Vector { | |
double x; | |
double y; | |
Vector(double x0 = 0, double y0 = 0) { | |
x = x0; | |
y = y0; | |
} | |
Vector(Point A, Point B) { | |
x = B.x - A.x; | |
y = B.y - A.y; | |
} | |
Vector operator-(const Vector &b) const { | |
return Vector(x - b.x, y - b.y); | |
} | |
}; | |
Vector operator+(const Vector &a, const Vector &b) { | |
return Vector(a.x + b.x, a.y + b.y); | |
} | |
Point operator+(Point A, Vector AB) { | |
return Point(A.x+AB.x,A.y+AB.y); | |
} | |
Vector operator*(const Vector &a, double x) { | |
return Vector(a.x * x, a.y * x); | |
} | |
Vector operator*(double x, const Vector &a) { | |
return Vector(a.x * x, a.y * x); | |
} | |
Vector operator/(const Vector &a, double x) { | |
return Vector(a.x / x, a.y / x); | |
} | |
istream &operator>>(istream &in, Point &P) { | |
in >> P.x >> P.y; | |
return in; | |
} | |
ostream &operator<<(ostream &out, Point &P) { | |
out << P.x <<" "<< P.y; | |
return out; | |
} | |
int main() { | |
Point A, B, C; | |
cin >> A >> B >> C; | |
Vector AB(A, B); | |
Vector AC(A, C); | |
Vector AM = AB + AC / 3; | |
Point M = A + AM; | |
cout<<M; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment