I have two pairs of lat/long coordinates that represent the top left and bottom right corners of a bounding box.
I have a third pair of lat/long coordinates representing a point within this bounding box.
How might I go about converting this point to a percentage of the X/Y position within the bounding box? For example, a point at X=50%
and Y=50%
would be bang in the centre of the bounding box.
It does of course need to take into account positive and negative coordinates.
Any guidance appreciated!
Best Answer
To solve this, you need to determine the ratio of the point's location (relative to the starting origin) to the length of the rectangle. The length is just the absolute difference of the x and y coordinates. In order to determine the point's location relative to the origin, just subtract the lower left coordinates from the point's coordinates. Finally, just divide the two to compute the percentage.
Here is a python function that should solve what you are looking for, where coord1, coord2, coord3 are tuples of the coordinates:
Or, if you prefer
The results: