示例#1
0
  public Shape prune() {
    Polygon result = new Polygon();

    for (int i = 0; i < getPointCount(); i++) {
      int next = i + 1 >= getPointCount() ? 0 : i + 1;
      int prev = i - 1 < 0 ? getPointCount() - 1 : i - 1;

      float dx1 = getPoint(i)[0] - getPoint(prev)[0];
      float dy1 = getPoint(i)[1] - getPoint(prev)[1];
      float dx2 = getPoint(next)[0] - getPoint(i)[0];
      float dy2 = getPoint(next)[1] - getPoint(i)[1];

      float len1 = MathUtils.sqrt((dx1 * dx1) + (dy1 * dy1));
      float len2 = MathUtils.sqrt((dx2 * dx2) + (dy2 * dy2));
      dx1 /= len1;
      dy1 /= len1;
      dx2 /= len2;
      dy2 /= len2;

      if ((dx1 != dx2) || (dy1 != dy2)) {
        result.addPoint(getPoint(i)[0], getPoint(i)[1]);
      }
    }

    return result;
  }
示例#2
0
 private float[] getNormal(float[] start, float[] end) {
   float dx = start[0] - end[0];
   float dy = start[1] - end[1];
   float len = MathUtils.sqrt((dx * dx) + (dy * dy));
   dx /= len;
   dy /= len;
   return new float[] {-dy, dx};
 }
示例#3
0
  protected void calculateRadius() {
    boundingCircleRadius = 0;

    for (int i = 0; i < points.length; i += 2) {
      float temp =
          ((points[i] - center[0]) * (points[i] - center[0]))
              + ((points[i + 1] - center[1]) * (points[i + 1] - center[1]));
      boundingCircleRadius = (boundingCircleRadius > temp) ? boundingCircleRadius : temp;
    }
    boundingCircleRadius = MathUtils.sqrt(boundingCircleRadius);
  }
示例#4
0
  public float[] getNormal(int index) {
    float[] current = getPoint(index);
    float[] prev = getPoint(index - 1 < 0 ? getPointCount() - 1 : index - 1);
    float[] next = getPoint(index + 1 >= getPointCount() ? 0 : index + 1);

    float[] t1 = getNormal(prev, current);
    float[] t2 = getNormal(current, next);

    if ((index == 0) && (!closed())) {
      return t2;
    }
    if ((index == getPointCount() - 1) && (!closed())) {
      return t1;
    }

    float tx = (t1[0] + t2[0]) / 2;
    float ty = (t1[1] + t2[1]) / 2;
    float len = MathUtils.sqrt((tx * tx) + (ty * ty));
    return new float[] {tx / len, ty / len};
  }
示例#5
0
 public float length() {
   return MathUtils.sqrt(x * x + y * y);
 }