• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drawing Triangular Grid

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am currently doing an assignment that involves Ehrenstein Illusions and I am kind of stuck on trying to draw a Triangle(the triangle on the right of the picture with 6 circles) where the squares are connected side by side. Any clues/help on how i can achieve this? Attached is a picture of what that triangular shape would look like.  Thanks in advance.

drawgrid.png
[Thumbnail for drawgrid.png]
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,

I think you should first create a square with the circles inside, as one figure. A Path2D object seems ideal for such a figure. It also has the advantage that you can use a coordinate system that is as comfortable as possible.

For instance, create a Path2D.Double,  and add the biggest square, with coördinates (-1,-1), (1,1) et cetera,  or other coördinates you like. Next, you know the diameter of your largest circle. Add it, and go on until you are satisfied. Now you have your basic figure. Look at the Shape and Path2D api how easy it is to transform these things. What is also necessary is a decent knowledge of coordinate system when it comes to drawing these things in a panel, at the required size. See for more information the Graphics2D api.

If this all sounds too complex, you can also draw your basic figure in a BufferedImage, thát you can also rotate and collect for your big triangle

Well, my initial thoughts.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can draw your diamond‑and‑circle with radius r and repeat it r to the right and r up. The sides of the diamond will be r×√2.
Then you can draw your diamond‑and‑circle with radius r and repeat it r to the right and r down.
Then you can ...
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer depends on which triangle you are talking about. It is pretty easy to figure out the triangle that connects the centers of the outer circles.
If you want the smallest triangle that completely encloses all of the circles, then the sides of the triangle have length ( 2 * r * ( 2 + sqrt(3) ) )
 
Andrew Tran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i got them to display similar to the assignment, but I have another question.
Where would i put the g.setColor and g.fillOval in order to make the lines Black and fill the circle with Green?
Initially, i thought i would put it in the drawDisc method where i tried
g.setColor(Color.BLACK);
g.fillOval(centerX,centerY,radius,0);
g.setColor(Color.GREEN);

It seems like only the lines get changed to black, but nothing is filled into the circles.

Thanks

this is my current code:

 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In  the code in your opening post, in the drawSubfigure-method, you have the correct sequence  already. You can use that same code in your drawDisc method., as far as I can tell.
 
Fred Kleinschmidt
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should really consider using Swing instead of AWT. Then you would create you own JPanel subclass, and do all of the drawing in its paintComponent() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic