Author | Message |
---|---|
dliang
Posts: 35
|
Posted 00:00 Feb 23, 2020 |
Does anyone know how to combine two rectangles into one? Every time I split the large rectangle, my method will return me an ArrayList of two small rectangles. Since it only changes either side of the rectangles, it will combine with the previous one. Then, there's will be ArrayList of three rectangles. How should I combine those two small rectangles? |
240812281
Posts: 7
|
Posted 01:46 Feb 23, 2020 |
Instead of thinking to combine the rectangles, I would rather think of building up to a rectangle with a size of 1200w x 700h. You are not changing either side of the rectangle, you are cutting one rectangle into 2 new rectangles (with the fraction formula) which when they both placed next to each other they should have the size of the original rectangle (I am using level 2 as an example) which will replace the original one. To answer your question, the reason why you have 3 rectangles in your array list might due to using the same array list which you initially have the original rectangle placed inside the array list and you add to that array list. Like Keenan mentioned in class, you are returning an array list with bunch rectangles, which when you use a for loop to display the rectangle, you should have 2 ^ (level - 1) rectangle(s) that builds up to 1200w x 700h I will recommend you to draw a simple binary tree of the recursion method output on paper or somewhere you like like Keenan showed in the class to visualize the recursion method and think backward. Although I've been to Keenan's office hour many times and ask him to explain the assignment, actually this assignment is quite simple once you figured out the sequence and logic behind it.
My answer may not the best, use my answer as a reference for now and wait for a better answer and explanation from Keenan. |
kknaur
Posts: 540
|
Posted 13:31 Feb 23, 2020 |
The previous answer given is good. What is drawn at the end of the recursion, is a picture made up of many smaller rectangles whose areas and configurations combine to form the first large rectangle. Imagine you are just dividing the initial area into an amount of triangles determined by the recursion level and the size and configuration of each rectangle is based on the randomness of how you divide. Kind of like each rectangle is a puzzle piece making up the larger picture. So yes, at the end of it all you will have a list of rectangles which when drawn will make up the entire picture. |