Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //x1y2-x2y1
- double line_and_point(double x1, double y1, double x2, double y2) {
- return x1 * y2 - x2 * y1;
- }
- bool check_segment_point(double x, double y, double x1, double y1, double x2, double y2) {
- double a = y2 - y1;
- double b = x1 - x2;
- double c = -(a * x2 + b * y2);
- return (a * x + b * y + c == 0 && (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) <= 0);
- }
- int main() {
- double x1, y1, x2, y2, x3, y3, x4, y4;
- cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
- double p1 = line_and_point(x2 - x1, y2 - y1, x3 - x1, y3 - y1);
- double p2 = line_and_point(x2 - x1, y2 - y1, x4 - x1, y4 - y1);
- double p3 = line_and_point(x4 - x3, y4 - y3, x1 - x3, y1 - y3);
- double p4 = line_and_point(x4 - x3, y4 - y3, x2 - x3, y2 - y3);
- if (p1 * p2 < 0 && p3 * p4 < 0 || (check_segment_point(x1, y1, x3, y3, x4, y4) ||
- check_segment_point(x2, y2, x3, y3, x4, y4) || check_segment_point(x3, y3, x1, y1, x2, y2) ||
- check_segment_point(x4, y4, x1, y1, x2, y2))) {
- cout << "YES";
- } else {
- cout << "NO";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement