-1

Currently, I have some Python code to obtain equidistant points on the surface of a sphere. Now, I want to edit this code to obtain equidistant points on the surface of a hemisphere. I assume that there is some simple parameter I need to change, but I am still a Python novice.

My code:

from numpy import pi, cos, sin, arccos, arange
import mpl_toolkits.mplot3d
import matplotlib.pyplot as plt

num_pts = 10000
indices = arange(0, num_pts, dtype=float) + 0.5

phi = arccos(1 - 2*indices/num_pts)
theta = pi * (1 + 5**0.5) * indices

x, y, z = cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi);

fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 75
fig_size[1] = 75
plt.rcParams["figure.figsize"] = fig_size
             
plt.figure().add_subplot(111, projection='3d').scatter(x, y, z, s=1);
plt.show()

#saves the coordinates
import numpy as np
import sys
points = np.transpose(np.array([x,y,z]))
#np.savetxt(sys.stdout, points, fmt="%.6f")
np.savetxt('data.txt', points, fmt="%.6f")

Thank you for your help!

Matthew
  • 21
  • 4
  • What do you suppose the key difference between a sphere and a hemisphere is? – Stephen Rauch Sep 03 '18 at 02:43
  • That z coordinates are always positive, so I can just eliminate all points that have a negative z component. However, I do not know if this will keep the points equidistant. – Matthew Sep 03 '18 at 03:35
  • All points will be equidistant from their nearest neighbor provided they were before you restricted z>0 – kevinkayaks Sep 03 '18 at 14:09

1 Answers1

1

Simplest way from what you have:

X = np.stack((x,y,z)) # stack up all coordinates 
mask = X[-1]>=0 # mask of elements where z coordinate larger than 0 
x,y,z = X.T[mask].T # mask out the elements where z coordinate < 0 

Then plot those points. you'll get a hemisphere I figure

kevinkayaks
  • 2,636
  • 1
  • 14
  • 30
  • Do you think that these coordinates will be equidistant by making this change? I am unfamiliar with the mask maneuver, but it graphically looks like the top half of an egg. – Matthew Sep 03 '18 at 03:34
  • The mask is just eliminating all points with z<0 without using a loop. – kevinkayaks Sep 03 '18 at 14:10
  • The points will remain equidistant if they were before this change. They aren't changed. Only half are deleted – kevinkayaks Sep 03 '18 at 14:11