tags:

views:

97

answers:

2

My program generated triangles automatically, however the arrangement of the triangles are random on JPanel. How can I plot the triangle in a grid order? Thanks.

EDITED:

for(int i = 0; i < 10; i++)    
{ 

  xCoord[0] = generator.nextInt(MAX_WIDTH);
  yCoord[0] = generator.nextInt(MAX_HEIGHT);

  xCoord[1] = (int) (xCoord[0] - xWidth);
  xCoord[2] = (int) (xCoord[1] + (xWidth/2));         

  yCoord[1] = yCoord[0];
  yCoord[2] = (int) (yCoord[1] - yHeight);  

  triangles.add( new Polygon(xCoord,yCoord, 3)); 
}

EDITED: OUTPUT DESIRED

How can I make the program generate many pattern but it MUST be in symmetrical form? e.g. left and right is symmetrical. I've tried to make Loop but so far it only generate 1 pattern. Help please :-(

*** ***      OR    **   **        OR  ***   ***    etc (as long as it is symmetrical)
*** ***            **   **             *     *
 *   *
+1  A: 
akf
Thanks, but how can I make it equal space from one triangles to another?
Jessy
e.g there are 10 triangles, how can I make it so the distance of one triangles from one another are fixed e.g. 20
Jessy
do you still want them to be randomly shaped?
akf
No. the triangle size are fixed. There are only one size of all.
Jessy
I need the arrangement of the triangles look symmetrical (gird order might be the best order), both from left and right side of the JPanel.
Jessy
that should be easy then. you can still take my code(link above) with its iteration and remove the randomizing aspect. just start with the triangle size you want and iterate, calculating the point offsets based on your cell.
akf
akf..you are my SAVIOUR....million thanks...:-)
Jessy
A: 

If your triangles are not all the same size, shape and orientation (or only approximately), then you could place them such that their circumcentre points are on a precise grid, giving you an approximation of being "equally" spaced. You can try other points, such as the centre of the nine-point circle to see if you can find a visually more pleasing arrangement.

See the [Wikipedia article on triangles][1] for more information about these points.

[1]: http://en.wikipedia.org/wiki/Triangle"Wikipedia article on triangles"

Galghamon