occw = {1:"COUNTER_CLOCKWISE",-1:"CLOCKWISE",2:"ONLINE_BACK",-2:"ONLINE_FRONT",0:"ON_SEGMENT"}
def ccw(p0, p1, p2):
a = p1 - p0
b = p2 - p0
# print(a,b,np.cross(a,b))
if (np.cross(a,b) > np.finfo(np.float).eps):
return 1 #COUNTER_CLOCKWISE
if (np.cross(a,b) < - np.finfo(np.float).eps):
return -1 # CLOCKWISE
if (np.dot(a,b) < - np.finfo(np.float).eps):
return 2 # ONLINE_BACK
if (np.linalg.norm(a) < np.linalg.norm(b)):
return -2 # ONLINE_FRONT
return 0 # ON_SEGMENT
a = []
a.append(map(int, raw_input().split()))
for aa in a:
t = np.array(aa).reshape(2,2)
p0 = t[0] #[::-1]
p1 = t[1] #[::-1]
# print(p0,p1)
n = input()
for i in range(n):
a = []
a.append(map(int, raw_input().split()))
for aa in a:
hn = np.array(aa).reshape(1,2)
hn = hn[0] #[::-1]
# print(hn)
print(occw[ccw(p0,p1,hn)])
More than 5 years have passed since last update.
Getting counter clockwise in python
Last updated at Posted at 2018-04-05
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
11