To get points which lie on the border of a rectangle, I use 4 for
loops. At first I thought about creating Rectangle
and using PathItterator
, but it confused me very much. Is there a better way than mine?
int r = 5;
int x = 0;
int y = 0;
int length = r * 2 + 1;
for (int i = 0; i < length; i++) {
System.out.print(String.format("(%d,%d) ", x - r + i, y - r));
}
System.out.println();
for (int i = 0; i < length; i++) {
System.out.print(String.format("(%d,%d) ", x - r + i, y + r));
} System.out.println();
for (int i = 0; i < length; i++) {
System.out.print(String.format("(%d,%d) ", x - r , y - r+i));
} System.out.println();
for (int i = 0; i < length; i++) {
System.out.print(String.format("(%d,%d) ", x + r , y - r+i));
}
System.out.println();