Jump to content

[SOLVED] Distance


Hooker

Recommended Posts

I'm trying to write a little script to calculate distances in a grid.. basicaly i have a grid 10,000 by 10,000 large.

 

In that grid quite randomly i have data on certain coordinates (i.e 395 | 900 etc), each coordinate on the grid has its own page, people take over their own part of the grid (basicaly there own place on a map) and fill information in on their grid, what i would like to do is calculate what other coordinates within 10 grid points in all directions are currently "inhabited", like that grid referrances neighbours.

 

I hope that makes sense, its kind of confusing for me to explain but if you need any more info just ask.

 

*edit*

Hopefully this will help:

grid.jpg

Link to comment
Share on other sites

in a mysql table, basicaly the table will be set out like so (sorry i didn't include this sooner :P):

 

UID | X_axis | Y_axis | Owner

 

UID = unique ID

X_axis = the x axis on the grid

Y_axis = the y axis on the grid

Owner = the owners UID

 

then the info held on the coordinates will be held in a different table and so will the info on the owner

Link to comment
Share on other sites

Hello,

 

This is not too difficult to solve with a query.

You have to query your database to select all the grids where X_axis is between 10 higher and 10 lower than the grid point you use as a reference and do the same thing for the Y_axis.

Of course that will always give you 441 rows (21 X 21)

so you can limit it with a where clause to only get the results with owners.

 

Is the Owner set to NULL or some other value when a grid place is not yet owned ?

 

how to do this practically.

 

get the grid coordinates from the gridpoint you are using to check if there are any neighbours within a 10 point.

example grid is X_axis=15 and Y_axis =20

put those values in a variable so you can use it in the query.

 

so your query would be something like

Select * from TABLENAME WHERE

X_axis > $x_axis_variable-10 AND

X_axis < $x_axis_variable+10 AND

Y_axis > $y_axis_variable-10 AND

Y_axis < $y_axis_variable+10 AND

Owner <> NULL;

 

Here are some potential problems.

you have to take in account that the X and Y position maybe lower than 10

for example gridpoint x=5 and y=3 That will give you negative values in your query but that should not be a real problem unless you have a numerical datatype with unsigned parameter

look here for more info

http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

 

I am sure you can change this

X_axis > $x_axis_variable-10 AND

X_axis < $x_axis_variable+10 AND

into something like this

$x_axis_variable+10 > X_axis > $x_axis_variable-10  AND

but I am not sure about syntax

 

hope that will get you started

kind regards

anatak

Link to comment
Share on other sites

Yes, a game.. still in planning, peicing things together before writing it all out but i'm trying to make it as graphical as possible (including maps showing where players are etc).

 

This part would basicaly be for how far a person can see as they move around and start villages etc

 

Nothing huge, just something to keep myself busy :)

Link to comment
Share on other sites

Yes, a game.. still in planning, peicing things together before writing it all out but i'm trying to make it as graphical as possible (including maps showing where players are etc).

 

This part would basicaly be for how far a person can see as they move around and start villages etc

 

Nothing huge, just something to keep myself busy :)

 

good idea. i once heard, 'don't document your code; code your documentation.'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.