rrgl# planes3d expands and draws the area based on the sphere's radius

The planes3d expands and draws the area based on the sphere's radius. Is there a way to suppress this? More desirable for me would be to clip the drawing area, though.

```
library(rgl)
z <- c(0,0,1)
y <- c(0,1,0)
x <- c(1,0,0)
bg3d(color = "white")
rgl.spheres(x, y, z, r = 0.02, color = "grey")
planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
view3d(theta=230, phi=-30, zoom=1, fov=0)
snapshot3d("r0_02.png", fmt="png", width=640, height=480, webshot=F)
clear3d()
rgl.spheres(x, y, z, r = 0.2, color = "grey")
planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
view3d(theta=230, phi=-30, zoom=1, fov=0)
snapshot3d("r0_2.png", fmt="png", width=640, height=480, webshot=F)
```

I'm expecting a workaround.

Solution

You shouldn't be using `planes3d()`

, which draws infinite planes, clipped to the bounding box.

There might be a workaround where you put the planes in one subscene and apply clipping there, and put the spheres in a different subscene with no clipping, but that would be tricky to implement.

A better approach is to use `quads3d()`

instead of `planes3d()`

. With your example, this would be

```
library(rgl)
z <- c(0,0,1)
y <- c(0,1,0)
x <- c(1,0,0)
corner1 <- c(1,1,2,2) # vector entry with corner of square
corner2 <- c(2,3,3,2) # other corner
bg3d(color = "white")
rgl.spheres(x, y, z, r = 0.2, color = "grey")
# planes3d(1, 0, 0, 0, col = 'blue', alpha = 0.6, size = 0)
quads3d(cbind(0, y[corner1], z[corner2]),
col = "blue", alpha = 0.6)
#planes3d(0, 1, 0, 0, col = 'red', alpha = 0.6, size = 0)
quads3d(cbind(x[corner1], 0, z[corner2]),
col = 'red', alpha = 0.6)
#planes3d(0, 0, 1, 0, col = 'green', alpha = 0.6, size = 0)
quads3d(cbind(x[corner1], y[corner2], 0),
col = 'green', alpha = 0.6)
view3d(theta=230, phi=-30, zoom=1, fov=0)
```

^{Created on 2024-01-11 with reprex v2.0.2}

In an earlier version of this answer, the spheres showed weird black blobs on the edges. That was due to a bug in `rgl`

that has been fixed. This image was drawn with the development version 1.2.10.

- Making an SEIR model parameter to depend on incidence of a compartment at each time step using ode function
- Applying strsplit() on data.frame results in unexpected output
- How to use pivot_longer to combine multiple columns in R with dplyr
- How to access and read files on an external hard drive using R and RStudio (Mac)?
- Subsetting netcdf files with multiple variables by time range
- Using enter key with action button in R Shiny
- How do I change the default library path for R packages
- Change background color between day and night in R base
- Balance of deposit account using tidyverse / mutate
- How to color in flextable with an as_grouped_data format with equal cells with same values
- Error in x[[1]] : subscript out of bounds
- How to configure chatbot using the shinyChatR package
- Remove rows with dplyr based on two conditions of two variables in R
- Calculate CDF of Weibull distribution in R
- How to delete all strings except some specific name in R?
- Assign date order (mm/dd/yyyy) to a date time character in R
- How to use conditional panel in R Shiny to only hide and show user inputs while still allowing underlying calculations to run?
- What are the ways for the faster processing of raster stack
- Regression with Panel Data (Wide)?
- R -How to pass value in mongolite Query
- Saving output from a function containing loop and ifelse
- A simple pivot_longer on 3D array in R?
- How to add a subscript in R
- MCMC and binary logistic regressions with zero events
- Summary statistics table in R Markdown
- calculate color scale range independently for each facet
- Remove variable label when using tbl_strata() and tbl_summary() from gtsummary package
- Adding superscript and minus signs to data and axis labels in ggplot2
- R equivalent of MATLAB's pascal(n, 1) different column signs
- Scraping federal note yield table from the treasury website