0

I can't figure out a code that fills trapezium with tiles.

To do a rectangle is easy because the x and y starts from 0:

for(int y=0; y<10; y++){
        for(int x=0; x<10; x++){
                //create a tile at (x ; y)
        }
    }

And it renders like this - photo

But in trapezium the x and y is changing every line - photo

How to create x, y loops so they fill like in the 2nd photo?

  • I think you need to define what you're looking for a little more accurately - are the tiles of fixed size for example? If so, there's no guarantee it will be possible to tile a trapezium like in the picture – rbennett485 Mar 26 '15 at 14:24

1 Answers1

0

You should have those 2 loops as for rectangle, but for every rectangle you should check is it inside of your trapezium or not and print it if it's in and just skip to next if it isn't.

And to check is it in or out you will need some math. You will basically need to test current tile position against of all 4 lines. To make it easier you can look at tile as a single point (i.e. center of tile).

By position I mean test on what side of the line that tile (point) is. So, if point is left from right line, right from left line, bellow the top line and above bottom line it means that point (title) is inside the trapezium and it should be drawn.

Check this, it it can help you with math:

How to tell whether a point is to the right or left side of a line

Community
  • 1
  • 1
MilanG
  • 6,994
  • 2
  • 35
  • 64