Finding the minimum and maximum values of X and Y coordinates.
#1

Hello there!

I'm sure this is a simple task but I've only just woken up and can't seem to process a way to do it in my head. So... I figured I'd ask y'all!

I have four sets of XYZ coordinates stored in a variable like this:

varName[playerid][0][0], varName[playerid][0][1], varName[playerid][0][2]

Basically, the first [0] after [playerid] determines the set of data. Like I said, I've got 4 sets so the first [0] can actually increase to be [3] at the maximum. Then the second argument (the [0], [1], and [2]) refers to the X, Y, and Z coordinate, respectively.

I'm trying to create some dynamic areas (using Incognito's streamer plugin), but I need to determine the minimum X coordinate, the minimum Y coordinate, the maximum X coordinate, and the maximum Y coordinate. Obviously, a loop will be necessary. However, I just can't seem to figure out how in the world to do this.

Any thoughts?
Reply
#2

Really easy actually, assume your first coordinate is your minimum then check every other coordinate to see if it is less do the opposite for the maximum.

pawn Код:
minxarray = 0;
minyarray = 0;
minzarray = 0;

maxxarray = 0;
maxyarray = 0;
maxzarray = 0;

for(new i = 1; i < sizeof(Array); i++)
{
      if(Array[i][0] < Array[minxarray][0]) minxarray = i;
      if(Array[i][1] < Array[minyarray][1]) minyarray = i;
      if(Array[i][2] < Array[minzarray][2]) minzarray = i;
}

for(new i = 1; i < sizeof(Array); i++)
{
      if(Array[i][0] > Array[maxxarry][0]) maxxarray = i;
      if(Array[i][1] > Array[maxyarry][1]) maxyarray = i;
      if(Array[i][2] > Array[maxzarry][2]) maxzarray = i;
}
Now you can add an area or whatever else you might want to do.

pawn Код:
AddArea(Array[minxarray], Array[minyarray], Array[minzarray], Array[maxxarray], Array[maxyarray], Array[maxzarray]);
Easy
Reply
#3

This is how I thought of this for Xmax:
pawn Код:
new Float:Xmax;

for(i=0; i< MAX_PLAYERS; i++)
{
    if (IsPlayerConnected(i))
    {
        for(new i2=0; i2<4; i2++)
        {
            Xmax=varName[i][0][0];
            if (i2>=1)
            {
                if (varName[i][i2][0]>varName[i][i2-1][0])
                {
                   Xmax=varName[i][i2][0];
                }
            }
        }
    }
}
Same goes for Ymax and Zmax.
Reply
#4

EDIT: Apparently, I can't do math today, either.

It's working, thanks [uL]Pottus.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)