Problem:


Counter-Clockwise

For given three points p0, p1, p2, print

COUNTER_CLOCKWISE

if p0, p1, p2 make a counterclockwise turn (1),

CLOCKWISE

if p0, p1, p2 make a clockwise turn (2),

ONLINE_BACK

if p2 is on a line p2, p0, p1 in this order (3),

ONLINE_FRONT

if p2 is on a line p0, p1, p2 in this order (4),

ON_SEGMENT

if p2 is on a segment p0p1 (5).

Input

xp0 yp0 xp1 yp1
q
xp20 yp20
xp21 yp21
...
xp2q-1 yp2q-1

In the first line, integer coordinates of p0 and p1 are given. Then, q queries are given for integer coordinates of p2.

Output

For each query, print the above mentioned status.

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xi, yi ≤ 10000

p0 and p1 are not identical.

Sample Input 1

0 0 2 0
2
-1 1
-1 -1

Sample Output 1

COUNTER_CLOCKWISE
CLOCKWISE

Sample Input 2

0 0 2 0
3
-1 0
0 0
3 0

Sample Output 2

ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT



Sample input:
0 0 2 0
2
-1 1
-1 -1


Sample output:
COUNTER_CLOCKWISE
CLOCKWISE

Submission status: Accepted

Solution code:
# coding: utf-8
import math
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        # self.z = 0
        self.length = math.sqrt(x**2 + y**2)

init_point = map(float,raw_input().split())
p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])

q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p2 = Point(xp2,yp2)
    p0p2 = Point(p2.x - p0.x, p2.y - p0.y)
    p0p1 = Point(p1.x - p0.x, p1.y - p0.y)
    p1p2 = Point(p2.x - p1.x, p2.y - p1.y)
    # ?????????????????????(3)(4)(5)
    if p0p1.x * p0p2.y - p0p1.y * p0p2.x == 0:
        if max(p0p1.length, p0p2.length) < p1p2.length: 
            print "ONLINE_BACK"
        elif p0p1.length < p0p2.length:
            print "ONLINE_FRONT"
        elif p0p1.length >= p0p2.length:
            print "ON_SEGMENT"
    else:
        # ?????????z????????????
        z = p0p1.x * p0p2.y - p0p1.y * p0p2.x
        if z > 0:
            print "COUNTER_CLOCKWISE"
        else:
            print "CLOCKWISE"

Submission status: Accepted

Solution code:
x0, y0, x1, y1 = map(int, input().split())
q = int(input())

p0, p1 = complex(x0, y0), complex(x1, y1)
p0p1 = p1 - p0

while q:
    q -= 1
    p2 = complex(*map(int, input().split()))
    p0p2 = p2 - p0
    prod_cross = p0p1.real * p0p2.imag - p0p1.imag * p0p2.real
    if abs(prod_cross) < 1e-6:
        if p0p1.real * p0p2.real >= 0 and p0p1.imag * p0p2.imag >= 0:
            print('ONLINE_FRONT' if abs(p0p1) < abs(p0p2) else 'ON_SEGMENT')
        else:
            print('ONLINE_BACK')
    else:
        print('COUNTER_CLOCKWISE' if prod_cross > 0 else 'CLOCKWISE')

Submission status: Accepted

Solution code:
x0, y0, x1, y1 = map(int, raw_input().split())
dx = x1 - x0
dy = y1 - y0
r = dx**2 + dy**2
for t in xrange(input()):
    x, y = map(int, raw_input().split())
    ex = x - x0
    ey = y - y0
    ov = dx*ey - dy*ex
    if ov > 0:
        print "COUNTER_CLOCKWISE"
    elif ov < 0:
        print "CLOCKWISE"
    else:
        iv = dx*ex + dy*ey
        if iv < 0:
            print "ONLINE_BACK"
        elif 0 <= iv <= r:
            print "ON_SEGMENT"
        else:
            print "ONLINE_FRONT"

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import enum


EPS = 1e-10


class PointsRelation(enum.Enum):
    counter_clockwise = 1
    clockwise = 2
    online_back = 3
    on_segment = 4
    online_front = 5


def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


def outer_product(v1, v2):
    return v1.real * v2.imag - v1.imag * v2.real


def judge_relation(p0, p1, p2):
    v1 = p1 - p0
    v2 = p2 - p0
    op = outer_product(v1, v2)
    if op > EPS:
        return PointsRelation.counter_clockwise
    elif op < -EPS:
        return PointsRelation.clockwise
    elif inner_product(v1, v2) < -EPS:
        return PointsRelation.online_back
    elif abs(v1) < abs(v2):
        return PointsRelation.online_front
    else:
        return PointsRelation.on_segment


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        ans = judge_relation(p0, p1, p2)
        if ans == PointsRelation.counter_clockwise:
            print("COUNTER_CLOCKWISE")
        elif ans == PointsRelation.clockwise:
            print("CLOCKWISE")
        elif ans == PointsRelation.online_back:
            print("ONLINE_BACK")
        elif ans == PointsRelation.online_front:
            print("ONLINE_FRONT")
        else:
            print("ON_SEGMENT")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

x0,y0,x1,y1 = map(float, raw_input().split())
q = int(raw_input())
for _ in xrange(q):
  x2,y2 = map(float, raw_input().split())
  ax = x1-x0
  ay = y1-y0
  bx = x2-x0
  by = y2-y0
  # check sin is positive or negative
  sin = ax*by-ay*bx
  if sin == 0:
    if(ax*bx < 0 or ay*by < 0):
      print "ONLINE_BACK"
    else:
      if math.fabs(bx) > math.fabs(ax) or math.fabs(by) > math.fabs(ay):
        print "ONLINE_FRONT"
      else:
        print "ON_SEGMENT"
  elif sin > 0:
    print "COUNTER_CLOCKWISE"
  else:
    print "CLOCKWISE"

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
0 0 2 0
3
-1 0
0 0
3 0

output:
ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT
"""

import sys

EPS = 1e-9


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def calc_distance(p_info):
    for point in p_info:
        p2_real, p2_imag = map(int, point)
        p2 = p2_real + p2_imag * 1j
        a, b = p1 - p0, p2 - p0
        if cross(a, b) > EPS:
            print('COUNTER_CLOCKWISE')
        elif cross(a, b) < -1 * EPS:
            print('CLOCKWISE')
        elif dot(a, b) < -1 * EPS:
            print('ONLINE_BACK')
        elif abs(a) < abs(b):
            print('ONLINE_FRONT')
        else:
            print('ON_SEGMENT')
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    base_line = tuple(map(int, _input[0].split()))
    p0, p1 = (x + y * 1j for x, y in zip(base_line[::2], base_line[1::2]))

    q_num = int(_input[1])
    q_list = map(lambda x: x.split(), _input[2:])
    calc_distance(q_list)

Submission status: Accepted

Solution code:
class Point:
    def __init__(self, x , y):
        self.x = x
        self.y = y
    def __sub__(self, p):
        x_sub = self.x - p.x
        y_sub = self.y - p.y
        return Point(x_sub, y_sub)

class Vector:
    def __init__(self, p):
        self.x = p.x
        self.y = p.y
    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5

def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x

def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y

def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    cross_ab = cross(a, b)
    if cross_ab > 0:
        print("COUNTER_CLOCKWISE")
    elif cross_ab < 0:
        print("CLOCKWISE")
    elif dot(a, b) < 0:
        print("ONLINE_BACK")
    elif a.norm() < b.norm():
        print("ONLINE_FRONT")
    else:
        print("ON_SEGMENT")

import sys

file_input = sys.stdin

x_p0, y_p0, x_p1, y_p1 = map(int, file_input.readline().split())
p0 = Point(x_p0, y_p0)
p1 = Point(x_p1, y_p1)

q = map(int, file_input.readline())

for line in file_input:
    x_p2, y_p2 = map(int, line.split())
    p2 = Point(x_p2, y_p2)
    ccw(p0, p1, p2)

Submission status: Accepted

Solution code:
import sys
from itertools import starmap
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
p0, p1 = starmap(complex, zip(*[map(int, input().split())] * 2))
n = int(readline())
for _ in [0] * n:
    res = ccw(p0, p1, complex(*map(float, readline().split())))
    if res == COUNTER_CLOCKWISE: print("COUNTER_CLOCKWISE")
    elif res == CLOCKWISE: print("CLOCKWISE")
    elif res == ONLINE_BACK: print("ONLINE_BACK")
    elif res == ONLINE_FRONT: print("ONLINE_FRONT")
    else: print("ON_SEGMENT")

Submission status: Accepted

Solution code:
def dot(a,b):
    return a[0]*b[0] + a[1]*b[1]

def cross(a,b):
    return a[0]*b[1] - a[1]*b[0]

x0,y0,x1,y1 = [int(i) for i in input().split()] 
a = [x1-x0,y1-y0]

q = int(input())
for i in range(q):
    x2,y2 = [int(i) for i in input().split()]
    b = [x2-x0,y2-y0]
    crs = cross(a,b)
    if crs > 0 :
        print("COUNTER_CLOCKWISE")
    elif crs < 0 :
        print("CLOCKWISE")
    else :
        if dot(a,b) < 0 :
            print("ONLINE_BACK")
        elif dot(a,a) < dot(b,b) :
            print("ONLINE_FRONT")
        else :
            print("ON_SEGMENT")

Submission status: Accepted

Solution code:
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def Order(a,b):
    crs = cross(a,b)
    if crs > 0 : return "COUNTER_CLOCKWISE"
    elif crs < 0 : return "CLOCKWISE"
    else:
        if dot(a,b) < 0 : return "ONLINE_BACK"
        elif dot(a,a) < dot(b,b) : return "ONLINE_FRONT"
        else : return "ON_SEGMENT"

x0,y0,x1,y1 = [int(i) for i in input().split()] 
a = [x1-x0,y1-y0]

q = int(input())
for i in range(q):
    x2,y2 = [int(i) for i in input().split()]
    b = [x2-x0,y2-y0]
    print(Order(a,b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


class Point(object):
    epsilon = 1e-10

    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        else:
            self.x = x
            self.y = y

    # ????????????
    def __add__(self, other):
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return Point(other * self.x, other * self.y)

    def __truediv__(self, other):
        return Point(other / self.x, other / self.y)

    def __lt__(self, other):
        if self.x == other.x:
            return self.y < other.y
        else:
            return self.x < other.x

    def __eq__(self, other):
        from math import fabs
        if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
            return True
        else:
            return False

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        from math import sqrt
        return sqrt(self.norm())


class Vector(Point):
    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        elif isinstance(x, Point):
            self.x = x.x
            self.y = x.y
        else:
            self.x = x
            self.y = y

    # ????????????
    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return Vector(other * self.x, other * self.y)

    def __truediv__(self, other):
        return Vector(other / self.x, other / self.y)

    @classmethod
    def dot(cls, a, b):
        return a.x * b.x + a.y * b.y

    @classmethod
    def cross(cls, a, b):
        return a.x * b.y - a.y * b.x

    @classmethod
    def is_orthogonal(cls, a, b):
        return Vector.dot(a, b) == 0.0

    @classmethod
    def is_parallel(cls, a, b):
        return Vector.cross(a, b) == 0.0


class Segment(object):
    def __init__(self, p1=Point(), p2=Point()):
        if isinstance(p1, Point):
            self.p1 = p1
            self.p2 = p2
        elif isinstance(p1, tuple):
            self.p1 = Point(p1[0], p1[1])
            self.p2 = Point(p2[0], p2[1])

    @classmethod
    def is_orthogonal(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_orthogonal(a, b)

    @classmethod
    def is_parallel(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_parallel(a, b)


class Line(Segment):
    pass


class Cirle(object):
    def __init__(self, c=Point(), r=0.0):
        self.c = c
        self.r = r


def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    epsilon = 1e-10
    if Vector.cross(a, b) > epsilon:
        return 'COUNTER_CLOCKWISE'
    elif Vector.cross(a, b) < -epsilon:
        return 'CLOCKWISE'
    elif Vector.dot(a, b) < -epsilon:
        return 'ONLINE_BACK'
    elif a.norm() < b.norm():
        return 'ONLINE_FRONT'
    else:
        return 'ON_SEGMENT'


def main(args):
    x_p0, y_p0, x_p1, y_p1 = map(int, input().split())
    p0 = Point(x_p0, y_p0)
    p1 = Point(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        x_p2, y_p2 = map(int, input().split())
        p2 = Point(x_p2, y_p2)
        result = ccw(p0, p1, p2)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from math import sqrt
xp0, yp0, xp1, yp1 = map(int, input().split())
a = [xp0, yp0]
b = [xp1, yp1]
q = int(input())

CCW = {1: 'COUNTER_CLOCKWISE',
       2: 'CLOCKWISE',
       3: 'ONLINE_BACK',
       4: 'ONLINE_FRONT',
       5: 'ON_SEGMENT',}

def dot(a, b):
    return sum([i * j for i,j in zip(a, b)])

def sub(a, b):
    return [a[0] - b[0],a[1] - b[1]]

def cross(a, b):
    return  a[0] * b[1] - a[1] * b[0]

def _abs(a):
    return sqrt(a[0] ** 2 + a[1] ** 2)

def ccw(a, b, c):
    x = sub(b, a)
    y = sub(c, a)
    if cross(x, y) > 0: return 1
    if cross(x, y) < 0: return 2
    if dot(x, y) < 0: return 3
    if _abs(x) < _abs(y): return 4
    return 5

for i in range(q):
    c = list(map(int, input().split()))
    print(CCW[ccw(a, b, c)])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import collections
import math


class Vector2(collections.namedtuple("Vector2", ["x",  "y"])):

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector2(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vector2(self.x * scalar, self.y * scalar)

    def __neg__(self):
        return Vector2(-self.x, -self.y)

    def __pos__(self):
        return Vector2(+self.x, +self.y)

    def __abs__(self):  # norm
        return math.sqrt(float(self.x * self.x + self.y * self.y))

    def dot(self, other):  # dot product
        return self.x * other.x + self.y * other.y

    def cross(self, other):  # cross product
        return self.x * other.y - self.y * other.x


def getDistanceSP(segment, point):
    p = point
    p1, p2 = segment
    if (p2 - p1).dot(p - p1) < 0:
        return abs(p - p1)
    if (p1 - p2).dot(p - p2) < 0:
        return abs(p - p2)
    return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)


def getDistance(s1, s2):
    if 0:  # intersect
        return 0
    a, b = s1
    c, d = s2
    return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b))


def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if a.cross(b) > 0:
        return 1
    elif a.cross(b) < 0:
        return -1
    elif a.dot(b) < 0:
        return 2
    elif abs(a) < abs(b):
        return -2
    else:
        return 0


if __name__ == '__main__':

    a, b, c, d = map(int, input().split())
    p0 = Vector2(a, b)
    p1 = Vector2(c, d)
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        p2 = Vector2(e, f)
        ans.append(ccw(p0, p1, p2))
    dic = {1: "COUNTER_CLOCKWISE", -1: "CLOCKWISE",
           2: "ONLINE_BACK", -2: "ONLINE_FRONT", 0: "ON_SEGMENT"}
    for a in ans:
        print(dic[a])

Submission status: Accepted

Solution code:
import math

class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Vector():
    def __init__(self, start, end):
        self.x = end.x - start.x
        self.y = end.y - start.y
        self.r = math.sqrt(pow(self.x, 2) + pow(self.y, 2))
        self.theta = math.atan2(self.y, self.x)

x0, y0, x1, y1 = list(map(int, input().split(' ')))
p0, p1 = Point(x0, y0), Point(x1, y1)
vec1 = Vector(p0, p1)

q = int(input())
for i in range(q):
    x2, y2 = list(map(int, input().split(' ')))
    p2 = Point(x2, y2)
    vec2 = Vector(p0, p2)
    if vec2.r == 0:
        print('ON_SEGMENT')
    elif vec1.theta == vec2.theta:
        if vec1.r < vec2.r:
            print('ONLINE_FRONT')
        else:
            print('ON_SEGMENT')
    elif abs(vec1.theta - vec2.theta) == math.pi:
        print('ONLINE_BACK')
    elif (0 < vec2.theta - vec1.theta and vec2.theta - vec1.theta < math.pi)  or vec2.theta - vec1.theta < -1*math.pi:
        print('COUNTER_CLOCKWISE')
    elif (-1*math.pi < vec2.theta - vec1.theta and vec2.theta - vec1.theta < 0) or vec2.theta - vec1.theta > math.pi:
        print('CLOCKWISE')

Submission status: Accepted

Solution code:
import math
EPS=1e-10

#点类
class Point():

    def __init__(self,x,y):
        self.x=x
        self.y=y
    
    def __sub__(self,p):
        return Point(self.x - p.x, self.y - p.y);
    def __add__(self,p):
        return Point(self.x + p.x, self.y + p.y)
           
    def __mul__(self,a): #a: scalar
        return Point(self.x * a, self.y * a)
    def __truediv__(self,a): #a: scalar
        return Point(self.x / a, self.y / a)
   
    def __str__(self):
       return  str(self.x)+','+str(self.y)
    def __repr__(self):
        return  'Point('+str(self.x)+','+str(self.y)+')'
    
    def __lt__(self, other):    
        if self.y-other.y==0:
            return self.x<other.x
        else:
            return self.y<other.y
            
    def __eq__(self, other):    
        return abs(self.x-other.x)<EPS and  abs(self.y-other.y)<EPS


# 线段类
class Segment():
    def __init__(self,p1, p2):
        self.p1=p1
        self.p2=p2
    def __str__(self):
        return  'segment:('+str(self.p1)+';'+str(self.p2)+')'
    def __repr__(self):
        return  'segment:('+str(self.p1)+';'+str(self.p2)+')'


class Circle():
    def __init__(self,c, r):
        self.c=c
        self.r=r

    def __str__(self):
       return  'Circle:(center point: '+str(self.c)+'; radius: '+str(self.r)+')'
    def __repr__(self):
       return  'Circle:(center point: '+str(self.c)+'; radius: '+str(self.r)+')'
   
    
#定义多边形
class Polygon():
    def __init__(self,ps=[]):
        self.ps=ps
        self.size=len(ps)
  
    def __getitem__(self, i):#iter override 
        return self.ps[i]  
    def __setitem__(self,i,p): 
        self.ps[i]=p               
    def __iter__(self):     
        return self.ps  
    
    def addpoint(self,i,p):
        self.ps.insert(i,p)
        self.size+=1
    def delpoint(self,i):
        self.size-=1
        return self.ps.pop(i)
    def sortYX(self):
        self.ps.sort()
        #self.ps.sort(key=attrgetter('y','x'))
    def __str__(self):
       return  'Polygon:'+str(tuple(self.ps))
    def __repr__(self):
       return  'Polygon:'+str(tuple(self.ps))
        
    def __len__(self):
        return len(self.ps)
    def __eq__(self, other):  
         return self.ps==other.ps
    
    def draw(self):
      
       turtle.screensize(800,800,"black")
       #turtle.setup(width=0.9,height=0.9)
       turtle.title("Polygon convex hull")
       turtle.setworldcoordinates(-400,-400,400,400) 

       #print(turtle.screensize())
       #mywin = turtle.Screen()    
       #mywin.   
       t=turtle.Turtle() 
       #mywin=turtle.Screen()
       
       t.pencolor("red")
       for pt in self.ps:
           t.goto(pt.x,pt.y)
           t.dot(10,'white')
       
 

#***************************点、向量****************************

#向量的模的平方
def norm(p):  
    return p.x * p.x + p.y * p.y


#向量P的长度
def length(p):
    return math.sqrt(p.x * p.x + p.y * p.y)


# 向量的(点)内积, dot(a,b)=|a|*|b|*cos(a,b) (从a,到b的角)
# =============================================================================
# r=dot(a,b),得到矢量a和b的点积，如果两个矢量都非零矢量  
# r<0：两矢量夹角为钝角； 
# r=0：两矢量夹角为直角； 
# r>0：两矢量夹角为锐角  
# =============================================================================
def dot(a, b) :
    return a.x * b.x + a.y * b.y



# =============================================================================
# # 向量的（叉）外积 cross(a,b)=|a||b|*sin(a,b) (从a,到b的角)由a,b构成的平行四边的面积
# r=cross(a,b),得到向量a和向量b的叉积  
# r>0：b在矢量a的逆时针方向；  
# r=0：a,b 平行共线；  
# r<0：b在向量a的顺时针方向 
# =============================================================================
def cross( a, b) :
    return a.x * b.y - a.y * b.x

# 点p在线段s上的投影
def project(s, p):
    base = s.p2 - s.p1
    r = dot(p - s.p1, base) / norm(base)
    return s.p1 + base * r 


# 点a到点b的距离
def getDistance(a, b) :
    return length(a - b)

# 线段l和点p的距离
def getDistanceLP(l, p) :
    return abs( cross(l.p2 - l.p1, p - l.p1) / length(l.p2 - l.p1) )

#getDistanceLP(s3, p7)
    
#线段s与点p的距离
def getDistanceSP(s, p) :
    if (dot(s.p2 - s.p1, p - s.p1) < 0.0):
        return length(p - s.p1)
    if (dot(s.p1 - s.p2, p - s.p2) < 0.0):
        return length(p - s.p2)
    return getDistanceLP(s, p)

#print(getDistanceLP(s3, Point(5,5)))
#print(getDistanceSP(s3, Point(5,5)))


#*************************线段********************************/
# 线段s1，s2是否正交 <==> 内积为0
def isOrthogonalSG(s1, s2) :
    return abs(dot(s1.p2 - s1.p1, s2.p2 - s2.p1))<EPS


# 线段s1，s2是否平行 <==> 叉积为0
def isParallelLN(s1,s2) :
    return abs(cross(s1.p2 - s1.p1, s2.p2 - s2.p1))<0




# 逆时针方向ccw（Counter-Clockwise）
COUNTER_CLOCKWISE = 1;
CLOCKWISE = -1;
ONLINE_BACK = -2;
ONLINE_FRONT = 2;
ON_SEGMENT = 0;

def ccw(p0, p1, p2) :
    a = p1 - p0
    b = p2 - p0
    if (cross(a, b) > EPS):
        return COUNTER_CLOCKWISE
    if (cross(a, b) < -EPS):
        return CLOCKWISE
    if (dot(a, b) < -EPS):
        return ONLINE_BACK
    if (norm(a) < norm(b)):
        return ONLINE_FRONT
    
    return ON_SEGMENT;


def toleft(p0,p1,p2):
    a = p1 - p0
    b = p2 - p0  
    tmp=cross(a,b)
    if tmp > EPS:
        return 1
    elif abs(tmp)<EPS and norm(a)<=norm(b):
        return 2  #共线，p2在p0p1的右延长线上
    elif abs(tmp)<EPS and norm(a)>norm(b):
        return -2  #共线，p2在p0p1的left延长线上    
    else:
        return -1


#以线段s为对称轴与点p成线对称的点
def reflect(s, p) :
    return p + (project(s, p) - p) * 2.0

# 判断线段p1p2和线段p3p4是否相交
def intersectP4(p1, p2, p3, p4) :
    return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and \
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0


#判断线段s1和s2是否相交
def intersectSG(s1, s2) :
    return intersectP4(s1.p1, s1.p2, s2.p1, s2.p2)


# 线段s1和线段s2的距离
def getDistanceSG(s1, s2) :
    # 相交
    if (intersectSG(s1, s2)):
        return 0.0
    return min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),\
        getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))




s= [int(x) for x in input().split()]
p0=Point(s[0],s[1])
p1=Point(s[2],s[3])

q=int(input())
for i in range(0,q):
    s= [int(x) for x in input().split()]
    p2=Point(s[0],s[1])
    
    vector1=p1-p0
    vector2=p2-p0
    if cross(vector1,vector2)>0:
        print('COUNTER_CLOCKWISE')
    
    if cross(vector1,vector2)<0:
        print('CLOCKWISE')
        
    if cross(vector1,vector2)==0:
        if dot(vector1,vector2)<0:
            print('ONLINE_BACK')     
        elif dot(vector1,vector2)>=0 and length(vector1)>=length(vector2) : 
            print('ON_SEGMENT')
        elif dot(vector1,vector2)>0 and length(vector1)<length(vector2) : 
            print('ONLINE_FRONT')

Submission status: Accepted

Solution code:
# coding=utf-8


def cross_product(vect1, vect2):
    return vect1[0]*vect2[1] - vect1[1]*vect2[0]


def vector_plus(vect1, vect2):
    return [el1 + el2 for el1, el2 in zip(vect1, vect2)]


def vector_minus(vect1, vect2):
    return [el1 - el2 for el1, el2 in zip(vect1, vect2)]


def vector_product(vect1, vect2):
    return [el1 * el2 for el1, el2 in zip(vect1, vect2)]


def vector_divide(vect1, vect2):
    return [el1 / el2 for el1, el2 in zip(vect1, vect2)]


def which_place(origin, line_to1, line_to2):
    line1 = vector_minus(line_to1, origin)
    line2 = vector_minus(line_to2, origin)
    judge = cross_product(line1, line2)

    if judge > 0:
        return "COUNTER_CLOCKWISE"
    if judge < 0:
        return "CLOCKWISE"
    if judge == 0:
        try:
            judge2 = line2[0]/line1[0]
        except ZeroDivisionError:
            judge2 = line2[1]/line1[1]
        
        if judge2 < 0:
            return "ONLINE_BACK"
        if judge2 > 1:
            return "ONLINE_FRONT"
        else:
            return "ON_SEGMENT"


if __name__ == '__main__':
    xy_list = list(map(int, input().split()))
    p0_list = xy_list[:2]
    p1_list = xy_list[2:]
    Q = int(input())

    for i in range(Q):
        p2_list = list(map(int, input().split()))
        place = which_place(p0_list, p1_list, p2_list)
        print(place)

Submission status: Accepted

Solution code:
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def __add__(self,other):
        return Vector(self.x+other.x,self.y+other.y)
    
    def __sub__(self,other):
        return Vector(self.x-other.x,self.y-other.y)
    
    def __mul__(self,scalar):
        return Vector(self.x*scalar,self.y*scalar)
    def __rmul__(self, scalar):
        return Vector(self.x*scalar,self.y*scalar)
   
    def __repr__(self):
        return str([self.x,self.y])
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y-vector1.y*vector2.x


x1,y1,x2,y2 = map(float,input().split())
p1 = Vector(x1,y1)
p2 = Vector(x2,y2)

q = int(input())

for i in range(q):
    x,y = map(float,input().split())
    p3 = Vector(x,y)
    
    a = p2-p1
    v = p3-p1
    if cross(a,v) > 0:
        print('COUNTER_CLOCKWISE')
    elif cross(a,v) < 0:
        print('CLOCKWISE')
    else:
        if dot(a,v)<0:
            print('ONLINE_BACK')
        elif dot(a,v)>a.norm_2():
            print('ONLINE_FRONT')
        else:
            print('ON_SEGMENT')

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline


class Vector():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, vec):
        return Vector(self.x+vec.x, self.y+vec.y)

    def __sub__(self, vec):
        return Vector(self.x-vec.x, self.y-vec.y)

    def __mul__(self, sc):
        return Vector(self.x*sc, self.y*sc)

    def __truediv__(self, sc):
        return Vector(self.x/sc, self.y/sc)

    def __iadd__(self, vec):
        self.x += vec.x
        self.y += vec.y
        return self

    def __isub__(self, vec):
        self.x -= vec.x
        self.y -= vec.y
        return self

    def __imul__(self, sc):
        self.x *= sc
        self.y *= sc
        return self

    def __itruediv__(self, sc):
        self.x /= sc
        self.y /= sc
        return self

    def __str__(self):
        return '{:.9f} {:.9f}'.format(self.x, self.y)

    def __eq__(self, vec):
        return self.x == vec.x and self.y == vec.y

    def dot(self, vec):
        return self.x * vec.x + self.y * vec.y

    def cross(self, vec):
        return self.x * vec.y - self.y * vec.x

    def abs(self):
        return (self.x*self.x + self.y*self.y)**0.5

    def ortho(self):
        return Vector(-self.y, self.x)

x0, y0, x1, y1 = map(int, input().split())
p0 = Vector(x0, y0)
p1 = Vector(x1, y1)
v1 = p1-p0

for _ in [0]*int(input()):
    x, y = map(int, input().split())
    p2 = Vector(x, y)
    v2 = p2-p0

    det = v2.cross(v1)
    if det > 0:
        print('CLOCKWISE')
    elif det < 0:
        print('COUNTER_CLOCKWISE')
    elif v2.dot(v1) < 0:
        print('ONLINE_BACK')
    elif v2.dot(v2) > v1.dot(v1):
        print('ONLINE_FRONT')
    else:
        print('ON_SEGMENT')