# Calculation example

This step-by-step example shows how to calculate the geographic midpoint (center of gravity) for three cities: New York, Chicago, and Atlanta. The three cities will be weighted by time.

### Convert all coordinates into radians

All latitude and longitude data must be converted into radians. If the coordinates are in degrees.minutes.seconds format, they must first be converted into decimal format. Then convert each decimal latitude and longitude into radians by multiplying each one by PI/180 as in the table below.

City | DMS coordinates | Decimal | Radians | |
---|---|---|---|---|

New York lat | 40° 42' 51.6708" N | 40.7143528 | 0.710599509 | |

New York lon | 74° 0' 21.5022" W | -74.0059731 | -1.291647896 | |

Chicago lat | 41° 52' 41.2098" N | 41.8781136 | 0.73091096 | |

Chicago lon | 87° 37' 47.2722" W | -87.6297982 | -1.5294285 | |

Atlanta lat | 33° 44' 56.382" N | 33.7489954 | 0.58903108 | |

Atlanta lon | 84° 23' 16.7346" W | -84.3879824 | -1.47284814 |

### weighting factors

The three cities will be weighted by time. For each city, the time is converted into days.

New York, 3 years

w_{1} = 365.25*3 = 1095.75

Chicago, 2 years

w_{2} = 365.25*2 = 730.5

Atlanta, 1 year

w_{3} = 365.25*1 = 365.25

Note that instead of time, a simple weighting factor such as population could also have been stored in w_{1}, w_{2}, and w_{3}. If no weighting factor is desired, set w_{1}=1, w_{2}=1, and w_{3}=1. Now sum the weights for all three cities.

totweight=w_{1} + w_{2} + w_{3}

totweight=1095.75 + 730.5 + 365.25 = 2191.5

### Convert lat/long to cartesian (x,y,z) coordinates

formulas:

X_{1} = cos(lat_{1}) * cos(lon_{1})

Y_{1} = cos(lat_{1}) * sin(lon_{1})

Z_{1} = sin(lat_{1})

New York:

X_{1} = cos(0.710599509) * cos(-1.291647896)

= 0.20884915

Y_{1} = cos(0.710599509) * sin(-1.291647896)

= -0.728630226

Z_{1} = sin(0.710599509)

= 0.65228829

Chicago:

X_{2} = cos(0.73091096) * cos(-1.5294285)

= 0.03079231

Y_{2} = cos(0.73091096) * sin(-1.5294285)

= -0.74392960

Z_{2} = sin(0.73091096)

= 0.66754818

Atlanta:

X_{3} = cos(0.58903108) * cos(-1.47284814)

= 0.08131173

Y_{3} = cos(0.58903108) * sin(-1.47284814)

= -0.82749399

Z_{3} = sin(0.58903108)

= 0.55555565

### Compute combined weighted cartesian coordinate

X = (X_{1}*w_{1} + X_{2}*w_{2} + X_{3}*w_{3})/totweight

= (0.20884915*1095.75 + 0.03079231*730.5 + 0.08131173*365.25)/2191.5

= 0.12824063

Y = (Y_{1}*w_{1} + Y_{2}*w_{2} + Y_{3}*w_{3})/totweight

= ((-0.728630226)*1095.75 + (-0.74392960)*730.5 + (-0.82749399)*365.25)/2191.5

= -0.75020731

Z = (Z_{1}*w_{1} + Z_{2}*w_{2} + Z_{3}*w_{3})/totweight

= (0.65228829*1095.75 + 0.66754818*730.5 + 0.55555565*365.25)/2191.5

= 0.64125282

### Convert cartesian coordinate to latitude and longitude for the midpoint

Note that in Excel and possibly some other applications, the two parameters in the atan2 function must be reversed, for example: use atan2(X,Y) instead of atan2(Y,X).

Lon = atan2(y, x)

= (atan2(-0.75020731, 0.12824063)

= -1.40149245

Hyp = sqrt(x * x + y * y)

= sqrt(0.12824063*0.12824063 + (-0.75020731)*(-0.75020731))

= 0.76108913

Lat = atan2(z, hyp)

= atan2(0.64125282, 0.76108913)

= 0.70015084

### Convert midpoint lat and lon from radians to degrees

lat= 0.70015084 * (180/PI)

= 40.11568861

lon= -1.40149245* (180/PI)

= -80.29960280

The weighted midpoint is located near Washington, Pennsylvania.