Last active
May 13, 2020 22:56
-
-
Save yangyushi/12080a7f9bfe015d0bf4ee00a9250c29 to your computer and use it in GitHub Desktop.
generate random points on the surface of a sphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.pyplot import plot, scatter, imshow | |
from mpl_toolkits.mplot3d import Axes3D | |
N = 1000 | |
z = np.random.uniform(-1, 1, N) | |
phi = np.random.uniform(-np.pi, np.pi, N) | |
rxy = np.sqrt(1 - z**2) | |
x = rxy * np.cos(phi) | |
y = rxy * np.sin(phi) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ax.scatter(x, y, z, marker='+') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment