<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/how-to-find-equidistant-coordinates-between-two-locations-on-earth/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://fronkonstin.com/2017/02/13/how-to-find-equidistant-coordinates-between-two-locations-on-earth/"> R – Fronkonstin</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div class="twitter-share"><a target="_blank" class="twitter-share-button" rel="nofollow" href="https://twitter.com/intent/tweet?url=https%3A%2F%2Ffronkonstin.com%2F2017%2F02%2F13%2Fhow-to-find-equidistant-coordinates-between-two-locations-on-earth%2F&via=aschinchon">Tweet</a></div>
<blockquote><p>Here’s to the ones who dream<br>
foolish, as they may seem<br>
(The Fools Who Dream, ‘La La Land’ OST)</p>
</blockquote>
<p>One of the key points of <a target="_blank" rel="nofollow" href="https://fronkonstin.com/2017/01/16/the-meeting-point-locator/">The Meeting Point Locator</a> is to obtain an orthogonal great circle to the bearing defined by any two given locations on Earth. A great circle is the intersection of the sphere and a plane that passes through the center point of the sphere. In other words, a great circle is a <em>false</em> meridian. The <em>orthogonal</em> great circle to the direction defined by any two given locations is the one which passes by all equidistant points to both of them (at least this is what I call orthogonal great circle). This was my first approach to obtain it:</p>
<ul>
<li>Get the midpoint between the initial locations, let’s call it p<sub>1</sub></li>
<li>Calculate the direction (bearing angle) between the initial locations, let’s call it α</li>
<li>Obtain a very close point to p<sub>1</sub> (only 1 meter away) with bearing α+90, let’s call it p<sub>2</sub></li>
<li>Calculate the great circle which passes through p<sub>1</sub> and p<sub>2</sub></li>
</ul>
<p>This is the code I used in this first approach:</p>
<pre>
library(dplyr)
library(ggmap)
library(geosphere)
library(leaflet)
library(ggplot2)
library(scales)
library(extrafont)
windowsFonts(Garamond=windowsFont(&quot;Garamond&quot;))

#Starting places
place1=&quot;Madrid, Spain&quot;
place2=&quot;Toledo, Spain&quot;

# Call to Google Maps API to obtain coordinates of Starting places
p1=geocode(place1, output = &quot;latlon&quot;)
p2=geocode(place2, output = &quot;latlon&quot;)

#Midpoint of p1 and p2
mid=midPoint(p1, p2)

#Direction between p1 and p2
bea=bearingRhumb(p1, p2)

# Great circle between midpoint and 1-meter separated point with bearing bea+90
points=greatCircle(destPoint(p=mid, b=bea+90, d=1), mid, n=100)

# Arrange the points dependning on the distance to the input locations
data.frame(dist2p1=apply(points, 1, function (x) distGeo(p1, x)),
           dist2p2=apply(points, 1, function (x) distGeo(p2, x))) %>% 
  cbind(points) -> points

opts=theme(
  panel.background = element_rect(fill=&quot;gray90&quot;),
  panel.border = element_rect(colour=&quot;black&quot;, fill=NA),
  axis.line = element_line(size = 0.5, colour = &quot;black&quot;),
  axis.ticks = element_line(colour=&quot;black&quot;),
  panel.grid.major = element_line(colour=&quot;white&quot;, linetype = 2),
  panel.grid.minor = element_blank(),
  axis.text = element_text(colour=&quot;gray25&quot;, size=6, family = &quot;Garamond&quot;),
  axis.title = element_text(size=10, colour=&quot;gray10&quot;, family = &quot;Garamond&quot;),
  legend.key = element_blank(),
  legend.position = &quot;none&quot;,
  legend.background = element_blank(),
  plot.title = element_text(size = 14, colour=&quot;gray10&quot;, family = &quot;Garamond&quot;),
  plot.subtitle = element_text(size = 10, colour=&quot;gray20&quot;, family = &quot;Garamond&quot;))

ggplot(points, aes(x=dist2p1, y=dist2p2), guide=FALSE)+
  geom_abline(intercept = 0, slope = 1, colour = &quot;red&quot;, alpha=.25)+
  geom_point(colour=&quot;blue&quot;, fill=&quot;blue&quot;, shape=21, alpha=.8, size=1)+
  scale_x_continuous(label=scientific_format())+
  scale_y_continuous(label=scientific_format())+
  labs(title=paste(place1,&quot;and&quot; ,place2, sep=&quot; &quot;),
       subtitle=&quot;Equidistant points (2nd approach)&quot;,
       x=paste(&quot;Distance to&quot; ,place1, &quot;(Km)&quot;, sep=&quot; &quot;),
       y=paste(&quot;Distance to&quot; ,place2, &quot;(Km)&quot;, sep=&quot; &quot;))+opts

#Map
points %>% 
  leaflet() %>% 
  addTiles(urlTemplate = &quot;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&quot;) %>% 
  addCircleMarkers(
    lng=points$lon, lat=points$lat,
    radius = 6,
    color = &quot;blue&quot;,
    stroke = FALSE, fillOpacity = 0.5) %>% 
  addCircleMarkers(
    lng=c(p1$lon, p2$lon), lat=c(p1$lat, p2$lat),
    radius = 6,
    color = &quot;red&quot;,
    stroke = FALSE, fillOpacity = 0.5)
</pre>
<p>I was pretty sure that all points of this last great circle must be equidistant to the initial locations but I was wrong. When the starting points are enough close, everything goes well. This is an example with Madrid and Toledo (separated only by 67 kilometers) as starting points. The following plot shows the distance to Madrid and Toledo of 100 points on the great circle obtained as I described before:</p>
<p><img data-image-description="" data-orig-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/MadToledo.png?fit=1228%2C1215&amp;ssl=1" data-orig-size="1228,1215" data-image-title="MadToledo" class="wp-image-3865" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="3865" data-permalink="https://fronkonstin.com/2017/02/13/how-to-find-equidistant-coordinates-between-two-locations-on-earth/madtoledo/" alt="" data-medium-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/MadToledo.png?fit=300%2C297&amp;ssl=1" data-large-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/MadToledo.png?fit=604%2C598&amp;ssl=1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/MadToledo_def.png?resize=604%2C598&ssl=1"><br>
This map shows also these 100 points (in blue) as well as the starting ones (in red):</p>
<p><br>
<iframe height="500" width="100%" src="https://fronkonstin.com/wp-content/uploads/2017/02/MadToledo.html"></iframe>
</p>
<p>Quite convincent. But this is what happens when I choose Tokyo and New York (10.873 kms. away) as the starting points:</p>
<p><img alt="" class="wp-image-3866" src="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC_def.png?resize=604%2C598&ssl=1" data-recalc-dims="1"><br>
And the map:</p>
<p><br>
<iframe height="500" width="100%" src="https://fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC.html"></iframe>
</p>
<p>To be honest, I do not know why this happens but, based on the success obtained using close starting points, the final solution was simple: bring the starting points closer preserving the original midpoint. This was my second (and definitive) try:</p>
<p><img data-image-description="" data-orig-file="https://i1.wp.com/fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC.png?fit=1228%2C1215&amp;ssl=1" data-orig-size="1228,1215" data-image-title="TokyoNYC" data-comments-opened="1" class="wp-image-3866" data-recalc-dims="1" data-attachment-id="3866" data-permalink="https://fronkonstin.com/2017/02/13/how-to-find-equidistant-coordinates-between-two-locations-on-earth/tokyonyc/" alt="" data-medium-file="https://i1.wp.com/fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC.png?fit=300%2C297&amp;ssl=1" data-large-file="https://i1.wp.com/fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC.png?fit=604%2C598&amp;ssl=1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/TokyoNYC2_def.png?resize=604%2C598&ssl=1"><br>
And the map:</p>
<p><br>
<iframe height="500" width="100%" src="https://fronkonstin.com/wp-content/uploads/2017/02/TokyoNY2.html"></iframe>
</p>
<p>Mission accomplished. The final code:</p>
<pre>
library(dplyr)
library(ggmap)
library(geosphere)
library(leaflet)
library(ggplot2)
library(scales)
library(extrafont)
windowsFonts(Garamond=windowsFont(&quot;Garamond&quot;))

# Starting places
place1=&quot;Tokyo, Japan&quot;
place2=&quot;New York, USA&quot;

# Call to Google Maps API to obtain coordinates of Starting places
p1=geocode(place1, output = &quot;latlon&quot;)
p2=geocode(place2, output = &quot;latlon&quot;)

# Midpoint of p1 and p2
mid=midPoint(p1, p2)
# Distance between p1 and p2
dist=distGeo(p1, p2)
# A simple piece of code to bring the starting points closer preserving the original midpoint
 x=p1
 y=p2
 while(dist>1000000)
 {
   x=midPoint(mid, x)
   y=midPoint(mid, y)
   dist=distGeo(x, y)
}
# Direction between resulting (close) points
bea=bearingRhumb(x, y)
# Great circle between midpoint and 1-meter separated point with bearing bea+90
points=greatCircle(destPoint(p=mid, b=bea+90, d=1), mid, n=100)

# Arrange the points dependning on the distance to the input locations
data.frame(dist2p1=apply(points, 1, function (x) distGeo(p1, x)),
           dist2p2=apply(points, 1, function (x) distGeo(p2, x))) %>% 
  cbind(points) -> points

opts=theme(
  panel.background = element_rect(fill=&quot;gray90&quot;),
  panel.border = element_rect(colour=&quot;black&quot;, fill=NA),
  axis.line = element_line(size = 0.5, colour = &quot;black&quot;),
  axis.ticks = element_line(colour=&quot;black&quot;),
  panel.grid.major = element_line(colour=&quot;white&quot;, linetype = 2),
  panel.grid.minor = element_blank(),
  axis.text = element_text(colour=&quot;gray25&quot;, size=6, family = &quot;Garamond&quot;),
  axis.title = element_text(size=10, colour=&quot;gray10&quot;, family = &quot;Garamond&quot;),
  legend.key = element_blank(),
  legend.position = &quot;none&quot;,
  legend.background = element_blank(),
  plot.title = element_text(size = 14, colour=&quot;gray10&quot;, family = &quot;Garamond&quot;),
  plot.subtitle = element_text(size = 10, colour=&quot;gray20&quot;, family = &quot;Garamond&quot;))

ggplot(points, aes(x=dist2p1, y=dist2p2), guide=FALSE)+
  geom_abline(intercept = 0, slope = 1, colour = &quot;red&quot;, alpha=.25)+
  geom_point(colour=&quot;blue&quot;, fill=&quot;blue&quot;, shape=21, alpha=.8, size=1)+
  scale_x_continuous(label=scientific_format())+
  scale_y_continuous(label=scientific_format())+
  labs(title=paste(place1,&quot;and&quot; ,place2, sep=&quot; &quot;),
       subtitle=&quot;Equidistant points (2nd approach)&quot;,
       x=paste(&quot;Distance to&quot; ,place1, &quot;(Km)&quot;, sep=&quot; &quot;),
       y=paste(&quot;Distance to&quot; ,place2, &quot;(Km)&quot;, sep=&quot; &quot;))+opts

points %>% 
  leaflet() %>% 
  addTiles(urlTemplate = &quot;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&quot;) %>% 
  addCircleMarkers(
    lng=points$lon, lat=points$lat,
    radius = 6,
    color = &quot;blue&quot;,
    stroke = FALSE, fillOpacity = 0.5) %>% 
  addCircleMarkers(
    lng=c(p1$lon, p2$lon), lat=c(p1$lat, p2$lat),
    radius = 6,
    color = &quot;red&quot;,
    stroke = FALSE, fillOpacity = 0.5)
</pre>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://fronkonstin.com/2017/02/13/how-to-find-equidistant-coordinates-between-two-locations-on-earth/"> R – Fronkonstin</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/IQDnnPsXTI0"></a></div>