Search code examples
pythonrandomsympysurface

Sampling random points from an implicitly defined surface in Python


I have an implicitly defined hypersurface in R^3, given by the zero level set of some function F:

F(x,y,z) = 0.

This part may not matter but: I want to plot this surface using the answers given in this or this thread.

Now I want to take a random sample of points from this surface. Does anyone know the best way to do this?


Solution

  • Well, simple way would be:

    1. Triangulate implicit surface. For implicit surface there are variations of marching cubes, I believe, already done.

    2. Given list of triangles, compute total area A=Sum(Ai), and probabilities pi = Ai/A. Probabilities would be normalized, Sum(pi)=1

    3. Sample particular triangle i using probabilities pi. Numpy.random.choice should help.

    4. Given selected triangle, generate uniform point in the triangle using Generate random locations within a triangular domain