Jump to content

[Solved] Finding coordinates from an outline


xilef11

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Exception in thread "main" java.lang.IllegalStateException: Current Java is 1.8.0_271 but we require at least 17         at net.minecraftforge.bootstrap.shim.Main.main(Main.java:32) Never have successfully gotten a minecraft server up and running so I thought i'd try again. Instant unfixable issue.  
    • What MC version? What's the IP? Are any mods needed to be able to join?
    • Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20   I found this code : KeyMapping.click(Minecraft.getInstance().options.keyUp.getKey()); But it doesn't seems to work   And i found this one : Minecraft.getInstance().options.keyUp.setDown(true); wich works but doesn't exactly do what i want , it doesn't release the key so for exemple i can't make him run. Minecraft.getInstance().options.keyUp.setDown(true); Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(true); doesn't make him run
    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
  • Topics

×
×
  • Create New...

Important Information

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