# Generate points on the surface of a semi-sphere

I would like to generate points on the surface of a semi-sphere (given the coordinates of its center), in a NON random way, not even quasi-random, possibly. I would prefer consecutive generated points to be spatially one near to the other, as far as it is possible. Is there a smart way of spanning the surface of a semi-sphere? Possibly in a scalable way, meaning that I can adjust the incremental step so that I can decide the resolution of the points.

I am writing it in C++, so if you have a piece of code in C++ it would be extremely useful. Otherwise, also pseudo-code would be extremely useful. Thank you.

edit retag close merge delete

Is this ros related at all? If for example you were wanting to publish a sphere rviz triangle list Marker there is https://github.com/lucasw/bgfx_ros/bl...

It is ROS related since I will want to spawn those points using the Rviz Markers, but I know how to do that. My problem is the generation of the points. If you know how to do that, it would be really helpful.

In the link I provided a set of points is generated in a sphere in a uniform way (though they get dense near the poles) in python which is as good as pseudo-code. By offsetting and scaling phi and theta it could be limited to a subsection of the sphere surface instead of the whole thing.

Consecutive points are near each other except when phi increments, but you could reverse the direction every other row. But for help with anything fancier and you are better off on a specific stackexchange site.

Great, this is exactly what I was looking for. Thank you very much. If you answer to the question here below, I will confirm yours as the right answer.

Sort by » oldest newest most voted Take a look at https://github.com/lucasw/bgfx_ros/bl... , it generates a complete sphere into an rviz Marker triangle list but you could add an angle offset to theta or phi and instead of multiplying by pi or 2*pi a smaller number will result in only a subsection of a sphere being covered by points:

def sphere_point(radius, theta, phi):
pt = Point()
sp = math.sin(phi)
cp = math.cos(phi)
pt.x = radius * cp * math.cos(theta)
pt.y = radius * cp * math.sin(theta)
return pt

...
num_lat = 20
num_long = 20
for i in range(num_lat):
phi1 = float(i) / float(num_lat) * math.pi - math.pi / 2.0
for j in range(num_long):
theta1 = float(j) / float(num_long) * 2.0 * math.pi

...

...

more

Also this method gives an excellent distribution: http://blog.marmakoide.org/?p=1

more