Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float vector_product(float ax, float ay, float bx, float by)
- {
- float val = ax * by - ay * bx;
- return val;
- }
- int main()
- {
- float x1, y1, x2, y2, x3, y3, x4, y4;
- float v1, v2, v3, v4;
- printf("Input coordinates: ");
- if (scanf("%f %f %f %f %f %f %f %f",
- &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) != 8)
- return 1;
- v1 = vector_product(x4 - x3, y4 - y3, x1 - x3, y1 - y3);
- v2 = vector_product(x4 - x3, y4 - y3, x2 - x3, y2 - y3);
- v3 = vector_product(x2 - x1, y2 - y1, x3 - x1, y3 - y1);
- v4 = vector_product(x2 - x1, y2 - y1, x4 - x1, y4 - y1);
- /*
- 1 - пересекаются
- 0 - не пересекаются
- */
- if (!v1 && !v2 && !v3 && !v4)
- printf("0\n");
- else if (((v1 * v2) <= 0) && ((v3 * v4) <= 0))
- printf("1\n");
- else
- printf("0\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement