1. adad

    Posted

    adad
Changes in title
+Getting counter clockwise in python
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,44 @@
+```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.
+* [eps](http://jn1inl.blog77.fc2.com/blog-entry-2002.html?sp)
+http://d.hatena.ne.jp/komiyam/20111210/1323503019
+* 外積
+http://www.wakhok.ac.jp/~asami/linalge/pdf/04-5-6.pdf
+http://jsciencer.com/unimath/linarge/3789/
+http://d.hatena.ne.jp/pashango_p/20090714/1247590272
+* sin
+http://manapedia.jp/text/2575