PDA

View Full Version : converting coordinates

Pandabeer
05-08-2009, 06:53 PM
im not pro @ maths, but this is what i want, i have some coordinates from a game (account info) and those are going from -9999.9999 till 9999.9999 so how to convert them to something that'll fit in a picture of 1536x1536 pixels (with imagecopy because ill put an icon over it)

mlseim
05-08-2009, 07:05 PM
So the exact center is 0,0 ?
And the upper-left corner is -9999, 9999?

Pandabeer
05-08-2009, 07:07 PM
So the exact center is 0,0 ?
And the upper-left corner is -9999, 9999?

center = 0,0 down-left corner = -9999,9999 ( dunno exact ) and upper right corner = 9999,9999 ( same )

mlseim
05-08-2009, 09:11 PM
See image attached ...

So, if I'm correct, you're placing your image (in red) onto the graph (in black).

Let us know if that is the correct idea of what you're doing.

EDIT:
Here's what I came up with ...

<?php
// Highlight point of an image based on coordinates.

// Make-up some Coordinates (for testing purposes)
\$x=-5000;
\$y=5000;

// Generate Image & determine width X Height
\$image = imagecreatefromjpeg("yourpicture.jpg");
\$imageWidth = imagesx(\$image);
\$imageHeight = imagesy(\$image);

// Determine the center of the image.
\$imageCenterWidth = \$imageWidth/2;
\$imageCenterHeight = \$imageHeight/2;

// Your coordinate system is -9999 to 9999,
\$divx = \$imageCenterWidth/9999;
\$divy = \$imageCenterHeight/9999;

\$px = \$imageCenterWidth + abs(round(\$x * \$divx));
if(\$x<0){
\$px = \$imageCenterWidth - abs(round(\$x * \$divx));
}

\$py = \$imageCenterHeight + abs(round(\$y * \$divy));
if(\$y>0){
\$py = \$imageCenterHeight - abs(round(\$y * \$divy));
}

// Do your pixel or ttf (text) thing here.
// Set the text or pixels at \$px,\$py

// Output & Free Memory