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:
def center(coord1, coord2, coord3):
x1,y1 = coord1
x2,y2 = coord2
x3,y3 = coord3
dx = float(abs(x1 - x2))
dy = float(abs(y1 - y2))
px = (x3 - x1)/dx
py = (y3 - y1)/dy
return px,py
Or, if you prefer
def center2(coord1, coord2, coord3):
px = (coord3[0] - coord1[0])/float(abs(coord1[0] - coord2[0]))
py = (coord3[1] - coord1[1])/float(abs(coord1[1] - coord2[1]))
return px,py
The results:
>>>center((-15,10), (10,18), (7.36, 12.9))
(0.8944, 0.36250000000000004)
Best Answer
for a small bbox, in a long/lat coordinate system, you can assume the earth is flat at that area and you can use the average of x and y: