How did he calculate triangle packing in this site https://www.engineeringtoolbox.com/circles-within-rectangle-d_1905.html This site calculate number of circle in a square using 2 methods , normal method and triangle method, the question is how did he get the maximum number by triangle method , cause i want to implement a code of this method.
1 Answers
The first row of circles extends down into the rectangle a distance $d$, the diameter of the circle.
The next, and subsequent, rows, extend an additional $\frac{\sqrt{3}d}{2}$ down the rectangle. Depending on how much slack is in the rectangle, there may be room for the same number of circles, or one fewer circle as shown in the illustration. You can change the width to $10.3$ in the linked webpage to see the difference.
To get the answer, you'll need to calculate two numbers for the rectangular case and three for the triangular case.
For the rectangular case, you need to know the number of circles per row, which is also the number of columns of circles $C$ and the number of rows of circles $R$.
To determine $C$, you can use something like a $Floor$ function:
$$C = Floor(w/d)$$
This gives the largest integer that's less than $w/d$.
Similarly for $R$:
$$R = Floor(h/d)$$
Then the number of circles is just $C\times R$.
For the triangular case, you'll need to know the number of circles in the "odd rows" starting on the top ($C_O$), the number of circles in the "even rows" ($C_E$), and the number of rows ($R$).
The number of circles in the odd rows is the same as above:
$$C_O = Floor(w/d)$$
The number of circles in the even rows is either the same as $C_O$, or one less than $C_O$, depending on the value of $w/d$. If the decimal part is greater than $0.5$, they're the same. If it's less than $0.5$, $C_E = C_O - 1$. You can calculate the decimal part $x$ like this:
$$x = (w/d) - Floor(w/d)$$
Finally, the number of rows, based on the description above, is
$$R = Floor\left(\left[\left(\frac{h}{d}-1\right)\frac{2}{\sqrt{3}}\right]+1\right)$$
From here, you calculate the number of odd rows, the number of even rows, and add up all of the circles in their respective rows. I'll leave that to you.
- 26,582
-
I appreciate your reply realy , Can be handled by code? – user732153 Dec 05 '19 at 21:32
-
@user732153 The page used code to count the circles and draw the diagrams, so I think that means the answer to your question is "yes". – David K Dec 05 '19 at 21:37
-
@user732153 Of course it can. Like David said, the webpage you referenced does it all with code. The ceiling() and/or floor() functions could be useful in your implementation. – John Dec 05 '19 at 21:38
-
Do you know how i can implement this code ? – user732153 Dec 05 '19 at 21:40
-
I waste all day trying and get no progress – user732153 Dec 05 '19 at 21:42
-
I outlined how to calculate what you need. I'll leave it to you to code. Have a nice weekend! – John Dec 06 '19 at 16:57
-
I didn't get what you mean , just go easy on me , i coded the first method but the second gives wrong results – user732153 Dec 06 '19 at 17:09
-
I will read what u edited again till i understand, thanks bro really <3 – user732153 Dec 06 '19 at 17:10
-
I edited the bottom part because I had made a mistake. I think it's correct now. – John Dec 06 '19 at 17:18
-
If you get some code going, you can ask the question on Stack Overflow, and refer to this question here. – John Dec 06 '19 at 17:19
-
Also it might help to draw things out and play with the webpage you linked to to see where things change. Good luck! – John Dec 06 '19 at 17:20
-
I understand what you wrote till now , and coded it but sometimes gives right values and sometimes wrong – user732153 Dec 06 '19 at 18:08
-
I didn't calculate odd row neither even , cause i am just researcher , doing projects , i just need to study this case and understand it then i code it – user732153 Dec 06 '19 at 18:11
-
Read this case the prof answered , https://math.stackexchange.com/questions/2548513/maximum-number-of-circle-packing-into-a-rectangle?answertab=active#tab-top – user732153 Dec 06 '19 at 18:22
-
I have problem to get row odd and row even , help bro – user732153 Dec 06 '19 at 19:48