I need some math advice… Or, at least I think i do.
I have a set of elements in my database which represents objects (like phyisical objects) with a position (x,y,z). These positions can be totally random, like object A has a position of 1532,3512,1500 and B has a position of 2421,4612,1234.
I’m trying to create a graphical map (using CSS) of the objects in 2D. So only the X and Y coords are being used. The map I want to draw on has a specific width and height. Now here’s the tricky part: I want the map to scale with the size of the map. Like, when there are 2 objects where one is at coord: 1,1 and the other on coord 3,3, I want object one to be in the top left corner of the map and the other in the bottom right.
So, here’s an example of my elements (objects):
database elements:
- [1] => x: 1254, y: 1642
- [2] => x: 2311, y: 2361
- [3] => x: 1732, y: 2351
- [4] => x: 1436, y: 3323
First, I take the minimum and maximum values of these elements to create a formula which lets the coords start at 0,0 and go from there.
so, let’s say the minumum x-value is 1254 in this example and Y is 1642.
I go in a for loop and do the following:
foreach( $this->db as $item )
{
$x = $this->value_x_max - $item['x'];
$y = $this->value_y_max - $item['y'];
}
The map size is 720×480 pixels. How do I create a formula which spreads out my objects across the map. It is important that the objects don’t go outside the map boundaries but also needs to be spread out. So if 2 objects have positions 1,1 and 1,2 for example, they need to be in the top left and bottom left corners.
Can anyone help me out with this?
Any help and advise appriciated!
Try this, but be aware, it’s just a realy quick and dirty raw sketch of what came to my mind. But maybe it’s enough to give you a jump start: