Polygon Selection

Discussion in 'Plugin Development' started by InspiredOne, Aug 12, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    InspiredOne

    so I have a plugin that lets you select polygon shaped regions by selecting the corners of the polygon in order with a stick. Each corner that is selected, a bedrock pillar is erected to indicate that the corner was successfully added to the polygon.

    I'm storing the Polygon as a Java built in polygon object, which works pretty well... but I've come across a problem that I was hoping somebody may have worked through before.

    +---+
    /-----
    /-----
    /-----
    +///+

    The + is the corner selected, the / is unprotected blocks, and the - is protected blocks. I'm having trouble figuring a way to make it claim the / blocks as well, but It's really tricky and i'm not sure what to do. When you get into weird shapes the solution becomes less and less obvious, but I hope I outlined the problem well enough.

    Now the reason for this strange behavior is due to the coordinate recorded when a player selects a corner. Right now I use the getBlockX() and getBlockZ() methods which report the same corner of every block. I realized that if I moved some coordinates I could make it work, but I couldn't find a rule that would give the correct results for every kind of polygon. If anybody has come across this problem and has a elegant solution, I could really use the guidance.
     
  2. Offline

    Jogy34

    You could try moving all of the corners out in both the X and Z directions then just ignore the blocks that make up the border of your new shape.
     
  3. Offline

    pzxc

    Compute the midpoint of X and Z by averaging the highest X and lowest X, and the highest Z and lowest Z.
    Then any coordinates that are on the half of the polygon where it isn't including the edge (by comparing X and Z to midpoints), increment or decrement the X or Z value (or both) to include the edge that's missing
     
  4. Offline

    InspiredOne


    I'm a bit confused about what you are describing... So I take all the highest Z of all the corners and the lowest Z of all the corners, and I find the midpoint, then I take the highest X and the lowest X and find the midpoint. I then combine these results to have a coordinate of the midpoint of the shape. I'm not sure what you are suggesting to do afterward though. Could you maybe elaborate more?
     
  5. Offline

    pzxc

    Don't combine them, keep the X midpoint and Z midpoint separate
    Say these are the coords of your polygon (x, z):
    1,1 ; 1,5 ; 5, 1; 5, 5

    Now say your polygon goes from 1,1 to 5,5 inclusive, but because the coordinates of a block matches the lower-left corner of the block, the edge from 1,5 to 5,5 doesn't include the blocks where Z is from 5 to 6 even though its part of the same block, the z coordinate 5 stops it. Same for the edge from 5,1 to 5,5.

    So the X midpoint is 3 and the Z midpoint is 3. Go through any of the coordinates and where you see X > 3, add 1, or Z > 3, add one

    so now your polygon is
    1,1 ; 1,6 ; 6, 1 ; 6, 6

    And includes all the appropriate edges
     
Thread Status:
Not open for further replies.

Share This Page