2018-10-03 18:59:01 +00:00
|
|
|
# setup: N = 5000 ; import numpy as np ; t0, p0, t1, p1 = np.random.randn(N), np.random.randn(N), np.random.randn(N), np.random.randn(N) # noqa
|
|
|
|
# run: arc_distance(t0, p0, t1, p1)
|
2018-04-05 22:07:33 +00:00
|
|
|
|
2018-10-03 18:59:01 +00:00
|
|
|
# pythran export arc_distance(float64 [], float64[], float64[], float64[])
|
2018-04-05 22:07:33 +00:00
|
|
|
|
|
|
|
import numpy as np
|
2018-10-03 12:38:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def arc_distance(theta_1, phi_1, theta_2, phi_2):
|
2018-04-05 22:07:33 +00:00
|
|
|
"""
|
|
|
|
Calculates the pairwise arc distance between all points in vector a and b.
|
|
|
|
"""
|
2020-06-28 18:24:40 +00:00
|
|
|
temp = (
|
|
|
|
np.sin((theta_2 - theta_1) / 2) ** 2
|
|
|
|
+ np.cos(theta_1) * np.cos(theta_2) * np.sin((phi_2 - phi_1) / 2) ** 2
|
|
|
|
)
|
2018-10-03 18:59:01 +00:00
|
|
|
distance_matrix = 2 * (np.arctan2(np.sqrt(temp), np.sqrt(1 - temp)))
|
2018-04-05 22:07:33 +00:00
|
|
|
return distance_matrix
|