These functions transform a mesh3d object or other
RGL objects by removing parts where fn
violates
the bound.
For clipMesh3d
the fn
argument can be any
of the following:
a character vector naming a function (with special
names "x"
, "y"
, and "z"
corresponding
to functions returning those coordinates)
a function
a numeric vector with one value per vertex
NULL
, indicating that the numeric values
are saved in mesh$values
For clipObj3d
any of the above except NULL
may be used.
If fn
is a numeric vector, with one value per vertex, those values will be
used in the test.
If it is a function with formal arguments x
,
y
and z
, it will receive the coordinates of
vertices in those arguments, otherwise it will receive
the coordinates in a single n x 3 matrix. The function
should be vectorized and return one value per vertex,
to check against the bound.
These operations are performed on the mesh:
First, all quads are converted to triangles.
Next, each vertex is checked against the condition.
Modifications to triangles depend
on how many of the vertices satisfy the condition
(fn >= bound
or fn <= bound
, depending on greater
)
for inclusion.
If no vertices in a triangle satisfy the condition, the triangle is omitted.
If one vertex satisfies the condition, the other two vertices
in that triangle are shrunk towards it by assuming fn
is locally linear.
If two vertices satisfy the condition, the third vertex
is shrunk along each edge towards each other vertex, forming a
quadrilateral made of two new triangles.
If all vertices satisfy the condition, they are included
with no modifications.
Modifications to line segments are similar: the segment
will be shortened if it crosses the boundary, or omitted
if it is entirely out of bounds. Points, spheres, text
and sprites will just be kept or rejected.
The minVertices
argument is used to improve the
approximation to the boundary when fn
is a non-linear
function. In that case, the interpolation described above
can be inaccurate. If minVertices
is set to a
positive
number (e.g. 10000
), then each object is modified
by subdivision to have at least that number of vertices,
so that pieces are smaller and the linear interpolation
is more accurate. In the clipObj3d
function,
minVertices
can be a vector, with entries corresponding
to each of the entries in ids
.