# Thread: Latitude Longitude Distance Alteration

1. ## Latitude Longitude Distance Alteration

I have been using the "Greater Circle Distance Formula" to determine the distance between to points of latitude/longitude (in miles).

R = 3963.0 * arccos[sin(lat1/57.2958) * sin(lat2/57.2958) + cos(lat1/57.2958) * cos(lat2/57.2958) * cos(lon2/57.2958 -lon1/57.2958)]

I now need to calculate a square of 'R' distnace from center point to tangent of side. I can do this by finding the upper lower left and right bounds to make a square. (i do realize laying this on the globe will give me a pin-cushion, but its close enough)

given what i need to accomplish(and my acceptance of the range of error) i can use the previous formula. But i am not well versed enough in advanced geometery to convert my formula to the 2 states i need it to be in:
1) lat2 = .... (where lon1 = lon2)
2) lon2 = ... (where lat1 = lat1)

any help or better formula to accomplish latitude/longitude ploting given, distance and 1 point would be mush appreciated.

Thanks
Tony

2. Originally Posted by dacablegy
I have been using the "Greater Circle Distance Formula" to determine the distance between to points of latitude/longitude (in miles).

R = 3963.0 * arccos[sin(lat1/57.2958) * sin(lat2/57.2958) + cos(lat1/57.2958) * cos(lat2/57.2958) * cos(lon2/57.2958 -lon1/57.2958)]

I now need to calculate a square of 'R' distnace from center point to tangent of side. I can do this by finding the upper lower left and right bounds to make a square. (i do realize laying this on the globe will give me a pin-cushion, but its close enough)

given what i need to accomplish(and my acceptance of the range of error) i can use the previous formula. But i am not well versed enough in advanced geometery to convert my formula to the 2 states i need it to be in:
1) lat2 = .... (where lon1 = lon2)
2) lon2 = ... (where lat1 = lat1)

any help or better formula to accomplish latitude/longitude ploting given, distance and 1 point would be mush appreciated.

Thanks
Tony
To simplify the formulas, I will work in terms of latitudes a1 and a2 and longitudes b1 and b2 in degrees and assume the arguments to the sin and cos functions are in degrees (to eliminate that pesky conversion to radians by dividing by 57.2958). Also let d = 24900/360, which is the factor for converting degrees to miles.

Then the great circle distance formula in miles and degrees is

R = d * arccos[sin(a1)sin(a2) + cos(a1)cos(a2)cos(b2 - b1)].

Assume (a1,b1) is given for the lower right corner of the square. I assume the goal is to find (a2,b2) for the upper left corner such that the distance along the bottom side between (a1,b1) and (a1,b2) is 2r miles and the distance along the right side between (a2,b1) and (a1,b1) is also 2r miles.

To find the distance along the bottom side between (a1,b1) and (a1,b2), set a2 = a1 and R = 2r in the great circle formula and solve for b2:

2r = d * arccos[sin(a1)^2 + cos(a1)^2 * cos(b2 - b1)],
cos(2r/d) = sin(a1)^2 + cos(a1)^2 * cos(b2 - b1),
cos(b2 - b1) = (cos(2r/d) - sin(a1)^2)/cos(a1)^2,

and finally

b2 = b1 + arccos[(cos(2r/d) - sin(a1)^2)/cos(a1)^2]. [**]

To find the distance along the right side between (a1,b1) and (a2,b1), set b2 = b1 and R = 2r in the great circle formula and solve for a2:

2r = d * arccos[sin(a1)sin(a2) + cos(a1)cos(a2)cos(b2 - b1)],

and since b2 - b1 = 0, cos(b2 - b1) = cos(0) = 1, and

cos(2r/d) = sin(a1)sin(a2) + cos(a1)cos(a2) = cos(a2 - a1)

using an angle difference identity, which yields

2r/d = a2 - a1 and

a2 = a1 + 2r/d. [***]

Comparing equations [***] and [**] shows converting differences in latitudes to miles can be done directly without reference to the longitude, but converting differences in longitudes to miles depends on the latitude. These are known facts but we've proved them here.

You said you wanted to find a square (pin cushion) where the distance from the center point to side is r. Equation [**] finds a pin cushion where the center of the bottom side to the right side is r. To use the center point, use (a1+a2)/2 instead of a1 in the formula:

b2 = b1 + arccos[(cos(2r/d) - sin((a1+a2)/2)^2)/cos((a1+a2)/2)^2]. [**]

3. ## Completed :)

Thanks, the coords i was looking for were actually:

1) (a1,b2) point directly right of center point
2) (a1,b1 - (b2-b1)) point directly left of center point
3) (a2,b1) point directly above center point
4) (a1 - (a2-a1), b1) point directly below center point

These edges allow me to make a a few simple bounds inwhich can compare data to see if it is inside or outside of ~radius bounds to the central point.

(The reason i cannot actually use a formula to determine within radius of center point is i can only use less-than, greater-than, or equal to compare latitude and longitude to a constant in my given task.)
So i will pre-calculate bounds, then this will allow me to ask is:
max lat > a2 > min lat
and
max lon > b2 > min lon
i will probably use more than one square to have a shape closer to a circle, my task is to find neaby things to the radius and going abit outside of that is with my availability to do so.