[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to code this?

Posted on 2002-06-20
9
Medium Priority
?
151 Views
Last Modified: 2010-05-02
Hi,

I want to write an application that given the size of a rectangle from a user, fill the rectangle randomly with 3 different sized squares and 2 different size rectangles.

What I need to know is how to represent this in code, how do I draw the rectangle then add one shape then another until it is all filled up without any spaces?

I dont want the actual code, but some idea of how to model it in code.

any thoughts?

see http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=progsoftgen&qid=20312622 for what it is I am trying to end up with.
0
Comment
Question by:gegege
9 Comments
 

Expert Comment

by:HobbitHouse
ID: 7096649
assuming you mean EXACTLY fill the given rectangle with exactly 3 square (of different sizes) and 2 rectangles (of different sizes), here's the algorithm:

make one square have one side equal to the shorter side of the rectangle.  This will leave you with a small rectangle.  Make the next square have one side equal to the short side of that rectangle.

... if you can't take it from there, I can't help you.

0
 
LVL 1

Author Comment

by:gegege
ID: 7096662
I am working on the logic side of things thats cool, but how do I actually in code say: put one square here then next to that put another square then another then put another square"

do you see what I mean?

how do I actually represent the shapes in code and then fill an object (the rectangle) with the shapes?
0
 

Expert Comment

by:HobbitHouse
ID: 7096870
just use the shape objects.  go to the toolbar & look for the thing that's a colored triangle and a colored circle on top of it with a colored rectangle in the background.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:HobbitHouse
ID: 7096874
sorry, it's a yellow circle on a red square on a blue rectangle
0
 

Expert Comment

by:HobbitHouse
ID: 7096875
sorry, it's a yellow circle on a red square on a blue rectangle
0
 
LVL 3

Accepted Solution

by:
Hornet241 earned 600 total points
ID: 7097249

The easiest would be to use a multi-dimensional array to represent the large rectangle

Dim lRec(4,6) as Integer

then fill the array with numbers representing the filling shapes as follows, use different numbers to represent different shapes and zero for blanks spaces

0 0 0 0 0 0 0
0 0 0 2 2 0 0
0 0 0 2 2 0 0
1 1 1 2 2 0 0
1 1 1 2 2 0 0

may be slow cycling through the array depending on your machine bu it should work

I have have used this same technique on a 3D space and it worked



0
 
LVL 1

Expert Comment

by:superchook
ID: 7097756
Look oat recursive routines...

That way, you can set rules for how many objects / types are allowed, and let the routine work against those rules to fill the available space.   You may like to use two sepraate functions (one for squares/rectangles, and one for triangles) for simplicity in coding.

e.g. Rule1: largest piece no larger than 30% of area, Rule 2: smallest piece no less than 10%... etc.  (optionally excluding the last piece from the rule (which will leave a rectabgle or triangle uncovered) - or notifying that the 'remaining' uncovered area is xxx%)

To do the drawing, I would prefer to use the line()function, (make sure they are closed!) and flood-fill later - unless there was a specific need to move the pieces after they were drawn... trying to rotate triangles would complicate the matter too much.






0
 
LVL 1

Author Comment

by:gegege
ID: 7098424
I think this is going in the right direction, but what I need to work out is how to decide which shape to put where.

Say I start from the bottom left I choose shape1 and I fill the rest of the row with different shapes.  Then I go to the next row, because some of them are different sizes, say the fist one I put down was 300 x 300 - a 400 x 400 wont fit so I need to move it one to the left and cut a bit off which is fine, but what happens if the next one I put in doesn't fit?  this picture should explain it a little better:

http://www.gingerpeople.f9.co.uk/rectangles.bmp

or maybe it wont :(
0
 
LVL 1

Author Comment

by:gegege
ID: 7103195
this is what I am doing.

cheers
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question