private boolean isConvex() {
    //float v[][] = polygon.vertices;
    //int n = polygon.vertexCount;
    //int j,k;
    //float tol = 0.001f;

    if (vertexCount < 3) {
      // ERROR: this is a line or a point, render as convex
      return true;
    }

    int flag = 0;
    // iterate along border doing dot product.
    // if the sign of the result changes, then is concave
    for (int i = 0; i < vertexCount; i++) {
      float[] vi = vertices[i];
      float[] vj = vertices[(i + 1) % vertexCount];
      float[] vk = vertices[(i + 2) % vertexCount];
      float calc = ((vj[TX] - vi[TX]) * (vk[TY] - vj[TY]) -
                    (vj[TY] - vi[TY]) * (vk[TX] - vj[TX]));
      if (calc < 0) {
        flag |= 1;
      } else if (calc > 0) {
        flag |= 2;
      }
      if (flag == 3) {
        return false;  // CONCAVE
      }
    }
    if (flag != 0) {
      return true;    // CONVEX
    } else {
      // ERROR: colinear points, self intersection
      // treat as CONVEX
      return true;
    }
  }