ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Generate points on the surface of a semi-sphere

asked 2017-03-13 10:46:14 -0600

HenrySleek gravatar image

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 flag offensive close merge delete

Comments

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...

lucasw gravatar image lucasw  ( 2017-03-13 10:56:39 -0600 )edit

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.

HenrySleek gravatar image HenrySleek  ( 2017-03-13 11:16:16 -0600 )edit

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.

lucasw gravatar image lucasw  ( 2017-03-13 11:46:54 -0600 )edit

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.

lucasw gravatar image lucasw  ( 2017-03-13 11:49:19 -0600 )edit

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.

HenrySleek gravatar image HenrySleek  ( 2017-03-14 08:30:28 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-03-14 10:38:53 -0600

lucasw gravatar image

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)
    pt.z = radius * sp
    return pt

...
radius = rospy.get_param("~radius", 2.0)
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

        ...

        p11 = sphere_point(radius, theta1, phi1)
        ...
edit flag offensive delete link more
0

answered 2017-03-22 05:41:29 -0600

HenrySleek gravatar image

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-03-13 10:46:14 -0600

Seen: 2,102 times

Last updated: Mar 22 '17