Solved

how to code this?

Posted on 2002-06-20
9
142 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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