1

I need to connect two points that lay on a sphere, in that way, that the line (edge) stays on the surface of the sphere and doesn't go through it.

For now I have:

  1. This sphere: Evenly distributing n points on a sphere

  2. The edges are plotted, but they go through the sphere.

  3. Desired result:

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
tory
  • 55
  • 1
  • 7
  • 1
    Use Polar coordinates, find the two angles that describe the two points, linearly interpolate between the two values, interpolate using little straight segments. – bracco23 Aug 24 '18 at 14:54
  • are you looking for the geodesic line (or great circle arc)? maybe this [question and answer](https://stackoverflow.com/q/27605242/8069403) is helpful – xdze2 Aug 24 '18 at 14:55
  • 1
    You need to look up the many geographical packages available. You'll need to work in spherical coordinates (polar is the 2D reduction), but the translation equations are included. – Prune Aug 24 '18 at 14:56
  • As a curiosity, what you're looking for has a name: **geodesic**. – Fernando D'Andrea Apr 12 '21 at 18:21

1 Answers1

1

Here is an implementation of the spherical linear interpolation or slerp proposed in this answer:

import numpy as np
import matplotlib.pylab as plt

def slerp(p1, p2, t):
    omega = np.arccos( p1.dot(p2) )
    sin_omega = np.sin(omega)    
    t = t[:, np.newaxis]
    return ( np.sin( (1-t)*omega )*p1 + np.sin( t*omega )*p2 )/sin_omega

p1 = np.array([1, 0, 0])
p2 = np.array([0, 1, 0])
t = np.linspace(0, 1, 30)

arc = slerp(p1, p2, t)

plt.plot( arc[:, 0], arc[:, 1] );
plt.axis('square');

which gives in 2D:

2D example

xdze2
  • 3,986
  • 2
  • 12
  • 29
  • @tory If an answer _"really helps!"_ it is customary for the OP to upvote and/or accept it. – gboffi Sep 07 '18 at 19:43