It's fairly straightforward to calculate a direct Euclidean distance between 2 points:
import torch
p1 = torch.tensor([1.0, 3.5])
p2 = torch.tensor([5.0, 9.2])
dis = torch.sum(torch.square(p1-p2))
dis
>>> tensor(48.4900)
However, how can I calculate the distance between 2 points on circle without going through the circle? That it, the distance on the circle's perimeter, in D-dimensional space.
Clearly, in 2D a circle is just a circle:
import numpy as np
import matplotlib.pyplot as plt
def circle_points(r, n):
circles = []
for r, n in zip(r, n):
t = np.linspace(0, 2*np.pi, n, endpoint=False)
x = r * np.cos(t)
y = r * np.sin(t)
circles.append(np.c_[x, y])
return circles
r = [2]
n = [20]
circles = circle_points(r, n)
fig, ax = plt.subplots()
for circle in circles:
ax.scatter(circle[:, 0], circle[:, 1])
ax.set_aspect('equal')
plt.show()
point_1 = circles[0][0]
point_2 = circles[0][11]
print('point_1: ', point_1, 'point_2: ', point_2)
>>> point_1: [2. 0.] point_2: [-1.90211303 -0.61803399]
While in 3D it will be a sphere, 4D hypersphere, etc.
