Andrew Tran

Greenhorn

Posts: 7

posted 1 year ago

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.

Piet Souris

Master Rancher

Posts: 2044

75

posted 1 year ago

- 1

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.

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.

Campbell Ritchie

Marshal

Posts: 56593

172

Fred Kleinschmidt

Bartender

Posts: 571

9

posted 1 year ago

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) ) )

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

posted 1 year ago

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:

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

Master Rancher

Posts: 2044

75