pmneila / PyMCubes

Marching cubes (and related tools) for Python
BSD 3-Clause "New" or "Revised" License
703 stars 87 forks source link

First example #32

Open RepRapLtd opened 3 years ago

RepRapLtd commented 3 years ago

I think the first example creates a sphere with the surface normals pointing the wrong way. The definition should be:

u = -((X-15)2 + (Y-15)2 + (Z-15)2 - 82)

ajh123 commented 1 year ago

I think the first example creates a sphere with the surface normals pointing the wrong way. The definition should be:

u = -((X-15)2 + (Y-15)2 + (Z-15)2 - 82)

I do agree but, Python 3.10.2 gives this error:

    u = -((X-15)**2 + (Y-15)**2 + (Z-15)2 - 82)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
pmneila commented 1 year ago

Hi,

It should be

u = -((X-15)**2 + (Y-15)**2 + (Z-15)**2 - 8**2)

Note that PyMCubes does not compute normals, as they can be computed in a post-processing step. The surface computed by PyMCubes is (or should be) agnostic to the sign of the distance function.

Following the standard approach of computing normals assuming counter-clockwise order of vertices, it is true that normals will point inwards or outwards depending on the sign of the distance function. This is, however, beyond the scope of this library (at least until normal computation is implemented inside PyMCubes). On top of that, whether the normals of a surface should point inwards or outwards is application-dependent, not an inherent property of the surface itself.

In any case, given that this is causing some confusion, I will update the example with an explanation about surface orientation in the next version.

Hope that clarifies the issue.

Best