Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- #define Vec Point
- const ld EPS = 1e-7;
- const ld Pi = 3.14159265358979323846;
- int sign(ld x) {
- if (x > EPS) return 1;
- if (x < -EPS) return -1;
- return 0;
- }
- ld sq(ld x) {
- return x * x;
- }
- struct Point {
- ld x, y;
- Point() : x(0), y(0) {}
- Point(ld _x, ld _y) : x(_x), y(_y) {}
- Point operator-(const Point& other) const {
- return Point(x - other.x, y - other.y);
- }
- Point operator+(const Point& other) const {
- return Point(x + other.x, y + other.y);
- }
- Point operator*(const ld& other) const {
- return Point(x * other, y * other);
- }
- // векторное произведение sin
- ld operator^(const Point& other) const {
- return x * other.y - y * other.x;
- }
- // скалярное произведение cos
- ld operator*(const Point& other) const {
- return x * other.x + y * other.y;
- }
- ld len2() const {
- return sq(x) + sq(y);
- }
- ld len() const {
- return sqrtl(len2());
- }
- Point norm() const {
- ld d = len();
- return Point(x / d, y / d);
- }
- bool operator<(const Point& other) const {
- if (sign(x - other.x) != 0) {
- return x < other.x;
- }
- else if (sign(y - other.y) != 0) {
- return y < other.y;
- }
- return false;
- }
- bool operator==(const Point& other) const {
- return sign(x - other.x) == 0 && sign(y - other.y) == 0;
- }
- Point ort() {
- return Point(-y, x);
- }
- void deb() const {
- std::cerr << "(" << x << ", " << y << ")" << std::endl;
- }
- };
- ostream& operator << (ostream& out, const Point& val) {
- return out << val.x << ' ' << val.y;
- }
- istream& operator >> (istream& in, Point& val) {
- return in >> val.x >> val.y;
- }
- struct Line {
- ld a, b, c;
- Line() : a(0), b(0), c(0) {}
- Line(const Point& x, const Point& y) : a(y.y - x.y), b(x.x - y.x), c(x.y* y.x - y.y * x.x) {
- ////// нормирование прямой
- //ld d = Point(a, b).len();
- //a /= d, b /= d, c /= d;
- //if (sign(a) == -1) {
- // a = -a;
- // b = -b;
- // c = -c;
- //}
- //else if (sign(a) == 0 && sign(b) == 0) {
- // a = 0;
- // b = -b;
- // c = -b;
- //}
- }/*
- Line norm() {
- ld d =
- }*/
- //ax+by+c=0
- ////y=-c/b
- //Line norm() {
- //
- //}
- Point get() {
- if (sign(b) != 0) {
- return Point(0, -c / b);
- }
- else
- return Point(0, -c);
- }
- bool operator==(const Line& other) const {
- return sign(a - other.a) == 0 && sign(b - other.b) == 0 && sign(c - other.c) == 0;
- }
- };
- ld dist_line(const Point& a, const Line& l) {
- return abs(l.a * a.x + l.b * a.y + l.c) / sqrtl(sq(l.a) + sq(l.b));
- }
- // проверка принадлежности точки отрезку
- bool is_point_on_seg(const Point& a, const Point& b, const Point& x) {
- // проверка в тупую
- return sign((a - b).len() - (a - x).len() - (b - x).len()) == 0;
- //if (a == b) {
- // return a == x;
- //}
- //else if (a == x || b == x) {
- // return true;
- //}
- //else {
- // return sign((x - a) ^ (b - a)) == 0 &&
- // sign((x - a) * (b - a)) == 1 &&
- // sign((x - b) * (a - b)) == 1;
- //}
- }
- Point point_to_seg(Point& x, Point& c, Point& d) {
- Line check(c, d);
- Vec k(check.a, check.b);
- Point suba = x + k;
- Point subb = x - k;
- //dis = dist_points(suba, a);
- if (is_point_on_seg(c, d, suba)) {
- return suba;
- }
- else {
- return subb;
- }
- }
- bool line_cross(const Line& a, const Line& b, Point& ans) {
- ld d = (a.b * b.a - a.a * b.b);
- if (sign(d) == 0)
- return false;
- ans.x = (b.b * a.c - b.c * a.b) / d;
- ans.y = (b.c * a.a - a.c * b.a) / d;
- return true;
- }
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- cout << fixed << setprecision(7);
- Point a, b, c;
- cin >> a >> b >> c;
- Line l1(a, (point_to_seg(a, b, c)));
- Line l2(c, (point_to_seg(c, a, b)));
- Point ans;
- line_cross(l1, l2, ans);
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement