Search code examples
rsurfacergl

Invert clipping in rgl::clipplanes3d


As per title.

I'm using the rgl package to plot a 3d surface.

At some point I want to clip out part of the plot, and so I use rgl::clipplanes3d. It works, but clips out the wrong side, leaving in the window just what I wanted to remove (and remove the part I was interested in).

The plane I'm using to clip is defined by:

h <- planes3d(a=0.2,b=1,c=0,d=-450)

I know it divides the surface into two parts and I want to get rid of one. But if I call

h <- clipplanes3d(a=0.2,b=1,c=0,d=-450)

the good part disappears and the wrong part stays. Is there some workaround to this, or some transformation I can apply to a, b, c, d so that clipping gets inverted?


Solution

  • This was a real question but I got inspired while writing it and I just found a solution.

    You just have to apply, pseudocoding, (a,b,c,d) -> (-a,-b,-c,-d).

    In other words, as the plane is defined by ax + by + cz + d = 0, you can multiply the equation by -1 and get the exact same plane. However, using -a,-b,-c,-d you'll invert the half-space stripped out by rgl::clipplanes3d.