Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Точка пересечения прямых
- //
- // Created by Владислав on 17/07/2019.
- // Copyright © 2019 Владислав. All rights reserved.
- //
- #include <iostream>
- using namespace std;
- double x1, y1, x2, y2, x3, y3, x4, y4, a1, b1, c1, a2, b2, c2, x, y;
- int main() {
- cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
- a1 = y1 - y2;
- b1 = x2 - x1;
- c1 = x1 * y2 - x2 * y1;
- a2 = y3 - y4;
- b2 = x4 - x3;
- c2 = x3 * y4 - x4 * y3;
- if(a1 * b2 - a2 * b1 == 0) {
- if(a1 * c2 - a2 * c1 == 0 && b1 * c2 - b2 * c1 == 0 ) {
- cout << 2 << '\n';
- } else {
- cout << 0 << '\n';
- }
- } else {
- x = (((c1 * b2) - (c2 * b1)) / ((a1 * b2) - (a2 * b1)));
- y = (((a1 * c2) -(a2 * c1)) / ((a1 * b2) - (a2 * b1)));
- x *= -1;
- y *= -1;
- if(a1 == a2 && b1 == b2 && c1 == c2) {
- cout << 2 << '\n';
- } else {
- cout.precision(15);
- cout << fixed << 1 << " " << x << " " << y << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement