Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello

 

I am creating a "block" that lifts terrain around it. The area to lift is defined by placing "marker" blocks in a connected shape that encloses the "lifter" block, on the same Y level. This has raised a few interesting questions:

 

1) Finding the outline:

This is the easy part, just search in any/all cardinal directions until a marker block is found (or a max distance is reached), then recursively find all connected marker blocks.

 

2) Making sure the outline is a closed shape around the lifter:

I would do this by making sure there is a marker block in all cardinal directions around the block, then checking that all marker blocks previously found have at least 2 other marker blocks connected to them. However, that looks like it could be slow.

 

3) Finding the area inside the outline

This is the part I don't know how to do, and also the more "general" problem: given a 2D grid with a known outline (and a "center" point), how to find the coordinates of all squares inside that outline?

 

Thoughts?

I could answer the third, simply take the position of the marker with lower x and z coords, do a for loop until you arrive to the coords of the marker with the highest coords (If that's the question)

Come and say hi at www.twitter.com/JoseluGames

  • Author
I could answer the third, simply take the position of the marker with lower x and z coords, do a for loop until you arrive to the coords of the marker with the highest coords (If that's the question)

That would only work if the area was rectangular...

 

I would make a Shape class (or use an existing one from a library) with a "containsPoint" method. Then you can implement this method however is needed for every type of shape.

The problem is that I can't know what the shape will be... all we have is the coordinates of the blocks that form the outline (which are connected), as well as the coordinates of a block somewhere inside the shape

  • Author

that... is a surprisingly simple algorithm, considering all I could think of involved vector math (and wouldn't work).  always google first  :-[

 

the only issue I see here is speed, since it looks like I'll have to iterate through all blocks within the "bounding rectangle" of the polygon, then check if it is on the inside, which involves iterating through all blocks on the outline (so at least width*height*perimeter checks). I have a similar concern with the check to make sure the border is actually closed. Not sure if something can be done about that though.

  • Author

I ended up using the first algorithm and ignoring the "closed edge" problem. I also make the checks more efficient by storing the edge as a Map<Xpos, Set<Zpos>>.

 

However, it seems that the area found is not correct (includes only the edge, but the edge that gets printed to the log is incomplete). I feel that I missed something obvious

Code on GitHub because reading code on the forums is painful

 

Edit: Yup, that was it: a few copy-paste derps in setting the NW and SE blocks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.