title: How to find rhumb line distance without crossing the date line?
body: <p>Seemingly quite a simple problem, but I just can't get it. Essentially I am trying to plot a bunch of lines of different weights showing international trade flows, via leaflet in R. I tried using great circle approaches but it doesn't give the effect I want. Instead I am trying to plot the arrows as one side of an ellipse of which the center line is the rhumb line between two countries.</p>
  <p>I don't want to cross the date line because then the chart looks horrible. However, the problem is that the implementation of rhumb line functions in <code>geosphere</code>, (<code>distRhumb</code>, <code>bearingRhumb</code> etc.) seem to only allow you to calculate the shortest distance (i.e. crossing the dateline as required).</p>
  <p>So my problem is given 2 points for which a connecting rhumb line would normally cross the dateline, let's say China and Canada, how do I accurately calculate the rhumb line distance and the rhumb line bearing <em>without</em> crossing the date line.</p>
  <p>so far I've tried this extremely hacky approach...</p>
  <pre class="lang-r prettyprint-override"><code>library(geosphere)
  
  rad2deg &lt;- function(rad) {(rad * 180) / (pi)}
  deg2rad &lt;- function(deg) {(deg * pi) / (180)}
  
  # China
  p1 &lt;- c(&quot;lon&quot;=104, &quot;lat&quot;=36.6)
  # Canada
  p2 &lt;- c(&quot;lon&quot;=-102, &quot;lat&quot;=57.7)
  
  # first get shortest distance rhumb bearing
  rbearing &lt;- (bearingRhumb(p1, p2) + 360) %% 360
  
  # and shortest distance rhumb distance
  shorter_dist &lt;- distRhumb(p1, p2)
  
  # reverse by flipping 180 degrees
  rbearing &lt;- rbearing - 180
  rbearing &lt;- (rbearing + 360) %% 360
  
  # and take a first guess using original distance
  p3 &lt;- destPointRhumb(p1, rbearing, shorter_dist)
  
  # now recalculate the distance and bearing
  # so we have 2 sides of a triangle and an angle
  dist2 &lt;- distRhumb(p3, p2)
  rbearing2 &lt;- (bearingRhumb(p3, p2)  + 360) %% 360
  A &lt;- 180 - abs(rbearing2 - rbearing)
  
  # try to use trigonometry to solve for the opposite side
  longer_dist &lt;- sqrt(shorter_dist^2 + dist2^2 - 2*(shorter_dist *dist2)*cos(deg2rad(A)))
  
  # and get a revised bearing
  bear_offset &lt;- rad2deg(asin(dist2*(sin(deg2rad(A))/longer_dist)))
  
  if (rbearing2 &gt; rbearing){
    longer_rbearing &lt;- rbearing + bear_offset
  } else {
    longer_rbearing &lt;- rbearing - bear_offset
  }
  
  </code></pre>
  <p>But that doesn't seem to work very well..</p>
  <p><a href="https://i.stack.imgur.com/pHhdc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pHhdc.png" alt="enter image description here" /></a></p>
  <p>There must be an easier way...?</p>