-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquadrantCheck.py
30 lines (29 loc) · 1 KB
/
quadrantCheck.py
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
def find_quadrant(x1, y1):
if x1 == 0 and y1 == 0:
return 0 # Origin
elif x1 == 0 and y1 > 0:
return 12 # Positive y-axis
elif x1 == 0 and y1 < 0:
return 34 # Negative y-axis
elif y1 == 0 and x1 > 0:
return 41 # Positive x-axis
elif y1 == 0 and x1 < 0:
return 23 # Negative x-axis
elif x1 > 0 and y1 > 0:
return 1 # First quadrant
elif x1 < 0 and y1 > 0:
return 2 # Second quadrant
elif x1 < 0 and y1 < 0:
return 3 # Third quadrant
elif x1 > 0 and y1 < 0:
return 4 # Fourth quadrant
# Example usage
print(find_quadrant(0, 0)) # Output: 0
print(find_quadrant(1, 1)) # Output: 1
print(find_quadrant(-1, 1)) # Output: 2
print(find_quadrant(-1, -1)) # Output: 3
print(find_quadrant(1, -1)) # Output: 4
print(find_quadrant(0, 5)) # Output: 12
print(find_quadrant(-5, 0)) # Output: 23
print(find_quadrant(0, -5)) # Output: 34
print(find_quadrant(5, 0)) # Output: 41