• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 21st, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <math.h>
3.
4. float vector_product(float ax, float ay, float bx, float by)
5. {
6.     float val = ax * by - ay * bx;
7.     return val;
8. }
9.
10. int main()
11. {
12.     float x1, y1, x2, y2, x3, y3, x4, y4;
13.     float v1, v2, v3, v4;
14.
15.     printf("Input coordinates: ");
16.
17.     if (scanf("%f %f %f %f %f %f %f %f",
18.     &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) != 8)
19.         return 1;
20.
21.     v1 = vector_product(x4 - x3, y4 - y3, x1 - x3, y1 - y3);
22.     v2 = vector_product(x4 - x3, y4 - y3, x2 - x3, y2 - y3);
23.     v3 = vector_product(x2 - x1, y2 - y1, x3 - x1, y3 - y1);
24.     v4 = vector_product(x2 - x1, y2 - y1, x4 - x1, y4 - y1);
25.
26.     /*
27.     1 - пересекаются
28.     0 - не пересекаются
29.     */
30.     if (!v1 && !v2 && !v3 && !v4)
31.         printf("0\n");
32.     else if (((v1 * v2) <= 0) && ((v3 * v4) <= 0))
33.         printf("1\n");
34.     else
35.         printf("0\n");
36.     return 0;
37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top