Jump to content

Define a matrix over an image


The_Dogg

Recommended Posts

Hi, I'm not an expert at PHP, but I'm trying  ;D

here is what I'm trying to do:
I have an image (which is a map of some sort) that is, let's say 500px X 800px, and I have to show on that map the location of certain elements, which the coordinates comes from a MySQL DB in the form (x= -115020 y= 32641).

The problem is that the coords I get from the DB are higher than the actual image size.

What I'm looking for is a way to define a matrix that would go from ie: X= -150000 Y= -75000 to X= 150000 Y= 75000 (with X=0 and Y=0 as the center of the image) so I can use the DB's coords to overlay an image on the exact location.

I'm using GD to overlay the image, i just need a way to define those coords on the image.

Thank you,
The_Dogg
Link to comment
https://forums.phpfreaks.com/topic/34748-define-a-matrix-over-an-image/
Share on other sites

hey dogg,
I will show you a simple to map the coor to a pixel on image.  This is an example on the horizonal x coordinate only.  y coordinate is similar.

[code]
// provide that the width of your image is 500px;
$xi_min = 0;  // the starting pixel of your image
$xi_max = 500; // the end pixel of your image

// assume that the x-coordiate go from 1000 to 2000
$xcoor_min = 1000;
$xcoor_max = 2000;

//assume that I have a coordiate which has x-coor is 1500;
$myX = 1500;

$result = ($myX - $xcoor_min) / ($xcoor_max - $xcoor_min);

$result = (($xi_max - $xi_min) * $result) + $xi_min;

echo $result;
[/code]

this code above will echo 250;
explain:  myX is 1500 while the coor ranged from 1000 to 2000, this result in the coor falling exactly half way on the image.
and there you go, the result is 250, which is half way on the image.

for y-coordinate, it is similar.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.