Description
Clipping a mesh involves three ingredients: the mesh to be clipped, a function associating a scalar to each vertex of the mesh, called the boundary function, and a threshold value. Then the clipping consists in removing the vertices whose corresponding values by the boundary function are greater (or smaller) than the the threshold. This is not enough: the boundary constructed in this way must be treated in order to be regular (smooth).
For example, in this SO post, the Togliatti surface, here constructed in a box:
has been clipped to a sphere.
The first method simply consists in removing the triangles which go outside this sphere, but this gives an irregular boundary:
For this particular case of a sphere, one can achieve a nice, smooth result by using spherical coordinates. This is possible also because the mesh is a mesh of an isosurface here.
But the SO member @user255430 (who is nobody but the author of the R package rgl) gave a more general solution by introducing the clipping with a boundary function. Here the function associates to each vertex its Euclidean norm and the threshold is the sphere radius. This method is not restricted to isosurfaces, it works for any mesh.
Remark. In the C++ library CGAL, one can clip a mesh by another mesh instead of clipping a mesh by a boundary function fn
. Then the clipping by the boundary function fn
is identical to the CGAL clipping by a mesh of the isosurface fn < threshold
.
Clipping is closely similar to intersection. Here is the intersection of a ball and a tetrahedron:
One can achieve the same result by clipping the tetrahedron to the sphere, in other words clipping with the boundary function fn(vertex) = norm(vertex)
.
The method described in the aforementionned SO post is public so we can borrow its ideas. Note that this is restricted to triangle meshes.
Where should we put the clipping function in Meshes.jl ? With the transforms?