Solved

how to code this?

Posted on 2002-06-20
9
143 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
 

Expert Comment

by:HobbitHouse
ID: 7096874
sorry, it's a yellow circle on a red square on a blue rectangle
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 64
Determine Range to Select 5 42
Sending a email via excel using vba 6 71
MS Date Picker 64 bit 32 bit issue 12 49
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now