Looping though 2D coordinates

Discussion in 'Plugin Development' started by Shadow_tingBRO, Jul 22, 2019.

Thread Status:
Not open for further replies.
  1. This is more of a math question ;) buuuuut so basically, Im making a grid that is made from marking loc1 and loc2 and then i want to get all the blocks in that grid. I have two locations, loc1 and loc2. They look a bit like this on a grid:

    loc1 ----------- B
    | |
    | |
    | |
    A----------------loc2

    ^grid didnt load properly but imagine the vertical line on the right connects from loc2 to B

    The y coordinates dont appeal to me because this is a 2D grid. So in my minecraft world, WITHOUT USING WORLEDIT API, what would the algorithm be for finding the x and z coordinates of A and B? I have thought about finding the hypotenuse from loc1 to loc2 but that wont work. And ideas? Hard part is that loc1 and loc2 could be negative and that could affect some stuff.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. @timtower could you show me some sample code of that? Im not really understsanding that yet.
     
  4. Offline

    timtower Administrator Administrator Moderator

    What part? Finding the min and max? Math.min, Math.max, looping? for(i=min;i<max;i++) ?
     
  5. So I think i said that wrong, I mean im finding the min and max of those locations but what does that actually do to help?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Shadow_tingBRO It makes sure that you know in which direction to iterate.
     
  7. @timtower Ohh I see what you mean thanks, but because i need to see the code to understand fully it do you mind showing me what that might look like (sorry)
     
  8. Offline

    timtower Administrator Administrator Moderator

    I pretty much gave it already, not gonna spoonfeed this.
     
  9. ite then ty tho
     
  10. Offline

    Kars

    Any coordinate being negative shouldn't affect the looping. What you would first do is define the corners like tim said. Then you loop starting at MinX to MaxX, and for every iteration you loop the Y's in the same way.

    This is what a loop looks like. You are able to nest loops.
    PHP:
    for (int i MinXMaxXi++) {
        
    // code here
    }
    Good luck.
     
Thread Status:
Not open for further replies.

Share This Page