## 题目描述：

LeetCode 469. Convex Polygon

Given a list of points that form a polygon when joined sequentially, find if this polygon is convex (Convex polygon definition).

Note:

1. There are at least 3 and at most 10,000 points.
2. Coordinates are in the range -10,000 to 10,000.
3. 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.

Example 1:

```[[0,0],[0,1],[1,1],[1,0]]

Explanation:
```

Example 2:

```[[0,0],[0,10],[10,10],[10,0],[5,5]]

Explanation:
```

## 题目大意：

1. 最少3个，最多10000个点
2. 坐标在-10,000 到 10,000之间。
3. 你可以假设组成的多边形总是简单多边形。换言之，我们确保每个顶点都是两条边的交点，其他边不会相互交叉。

## Python代码：

``````class Solution(object):
def isConvex(self, points):
"""
:type points: List[List[int]]
:rtype: bool
"""
def crossProduct(p0, p1, p2):
x0, y0 = p0
x1, y1 = p1
x2, y2 = p2
return (x2 - x0) * (y1 - y0) - (x1 - x0) * (y2 - y0)

size = len(points)
last = 0
for x in range(size):
p0, p1, p2 = points[x], points[(x + 1) % size], points[(x + 2) % size]
p = crossProduct(p0, p1, p2)
if p * last < 0:
return False
last = p
return True
``````

Pingbacks已关闭。