Skip to content
Advertisement

Using points to Plot a Sphere in Julia

I would like to sample N points (lets say N = 10000) on a sphere.
I know how to plot a 3D sphere. However, I am not sure how to use spherical coordinates for points.
(below is the code I used for the sphere)

using PyPlot
n = 100
u = range(0,stop=2*π,length=n);
v = range(0,stop=π,length=n);

x = cos.(u) * sin.(v)';
y = sin.(u) * sin.(v)';
z = ones(n) * cos.(v)';


surf(x,y,z, rstride=4, cstride=4)

Sphere

Advertisement

Answer

This will do the job:

scatter3D(vec(x),vec(y),vec(z);c="red",s=2)
surf(x,y,z, rstride=4, cstride=4)

enter image description here

Advertisement