Solved

how to code this?

Posted on 2002-06-20
9
145 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 122
Prevent user closing word document opened with VB6 6 78
Added a column screws up code 5 63
vbModal 12 57
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

820 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