Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@adad

Getting counter clockwise in python

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)])

Refs.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?