-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheredoiturn.c
62 lines (55 loc) · 1.55 KB
/
wheredoiturn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double slope(int a1, int a2, int b1, int b2) {
if (b1 == a1) {
// Vertical line, return a large value to simulate infinity
return INFINITY;
}
return (double)(b2 - a2) / (b1 - a1);
}
float area(int a1, int a2, int b1, int b2, int c1, int c2) {
float a = 0.5 * abs(a1 * (b2 - c2) + b1 * (c2 - a2) + c1 * (a2 - b2));
return a;
}
int main() {
int x1, y1, x2, y2, x3, y3;
scanf("%d%d", &x1, &y1);
scanf("%d%d", &x2, &y2);
scanf("%d%d", &x3, &y3);
if (area(x1, y1, x2, y2, x3, y3) == 0.0) {
printf("TOWARDS");
} else {
double slope1 = slope(x1, y1, x2, y2);
double slope2 = slope(x2, y2, x3, y3);
if (slope1 == 0 && isinf(slope2)) {
if (x3 < x2) {
printf("LEFT");
} else {
printf("RIGHT");
}
} else if (isinf(slope1) && slope2 == 0) {
if (y3 < y2) {
printf("LEFT");
} else {
printf("RIGHT");
}
} else if (fabs(slope1 * slope2 + 1) < 1e-9) { // Check if slopes are perpendicular
if (y3 > y2) {
printf("LEFT");
} else {
printf("RIGHT");
}
}
else if(slope(x1,y1,x2,y2)*slope(x2,y2,x3,y3)==-1)
{
if(y3>y2)
{
printf("LEFT");
}
else
printf("RIGHT");
}
}
return 0;
}