# 469. Convex Polygon

Given a list of points that form a polygon when joined sequentially, find if this polygon is convex [(Convex polygon definition)](https://en.wikipedia.org/wiki/Convex_polygon).

**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)](https://en.wikipedia.org/wiki/Simple_polygon). 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]]

Answer: True

Explanation:
```

**Example 2:**

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

Answer: False

Explanation:
```

```cpp
int crossProduct(const vector<int>& A, const vector<int>& B, const vector<int>& C) {
    int BAx = B[0] - A[0];
    int BAy = B[1] - A[1];
    int CBx = C[0] - B[0];
    int CBy = C[1] - B[1];
    return BAx * CBy - BAy * CBx;
}
bool isConvex(vector<vector<int>>& points) { // time: O(n); space: O(1)
    int n = points.size(), j, k, cross;
    bool positive_cross = false, negative_cross = false;
    for (int i = 0; i < n; ++i) {
        j = (i + 1) % n;
        k = (j + 1) % n;
        cross = crossProduct(points[i], points[j], points[k]);
        if (cross > 0) positive_cross = true;
        else if (cross < 0) negative_cross = true;
        if (positive_cross && negative_cross) return false;
    }
    return true;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jimmylin1991.gitbook.io/practice-of-algorithm-problems/math/469.-convex-polygon.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
