Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition).
Note:
There are at least 3 and at most 10,000 points.
Coordinates are in the range -10,000 to 10,000.
You may assume the polygon formed by given points is always a simple polygon (Simple polygon definition). In other words, we ensure that exactly two edges intersect at each vertex, and that edges otherwise don't intersect each other.
flag = 0 n = len(points) for i in range(n): # cur > 0 表示points是按逆时针输出的;cur < 0,顺时针 cur = cal_cross_product(points[i], points[(i + 1) % n], points[(i + 2) % n]) if cur != 0: # 说明异号, 说明有个角大于180度 if cur * flag < 0: returnFalse else: flag = cur returnTrue