Draw text using base graphics math plotting or LaTeX
plotmath3d.RdTo plot mathematical text, plotmath3d uses base graphics
functions to plot it to a .png file, then uses that
file as a texture in a sprite. latex3d uses the
xdvir package to render LaTeX code, then uses
the same approach to display it in rgl.
Usage
plotmath3d(x, y = NULL, z = NULL, text, cex = par3d("cex"),
adj = 0.5, pos = NULL, offset = 0.5,
fixedSize = TRUE, startsize = 480, initCex = 5,
margin = "", floating = FALSE, tag = "",
polygon_offset = material3d("polygon_offset"), ...)
latex3d(x, y = NULL, z = NULL, text, cex = par3d("cex"),
adj = 0.5, pos = NULL, offset = 0.5,
fixedSize = TRUE, startsize = 480, initCex = 5,
margin = "", floating = FALSE, tag = "",
polygon_offset = material3d("polygon_offset"),
verbose = FALSE, ...)Arguments
- x, y, z
Coordinates. Any reasonable way of defining the coordinates is acceptable. See the function
xyz.coordsfor details.- text
A character vector or (in
plotmath3d) expression. Seeplotmathfor how expressions are interpreted inplotmath3d. Inlatex3deach text entry should be a LaTeX fragment.- cex
Character size expansion.
- adj
One value specifying the horizontal adjustment, or two, specifying horizontal and vertical adjustment respectively, or three, for depth as well.
- pos, offset
Alternate way to specify
adj; seetext3d- fixedSize
Should the resulting sprite behave like the default ones, and resize with the scene, or like text, and stay at a fixed size?
- startsize, initCex
These parameters are unlikely to be needed by users.
startsizeis an over-estimate of the size (in pixels) of the largest expression. Increase this if large expressions are cut off.initCexis the size of text used to form the bitmap. Increase this if letters look too blurry at the desired size.- margin, floating, tag, polygon_offset
material3dproperties for the sprites.- verbose
If
TRUE,latex3dwill print intermediate results for debugging.- ...
For
plotmath3d, additional arguments to pass totextwhen drawing the text. Forlatex3d, additional arguments to pass toxdvir::latexGrob.
Note
The text3d function passes calls to
plotmath3d if its usePlotmath argument is
TRUE.
This is the default value if its
texts argument looks like an expression.
The latex3d function produces nicer looking results
than plotmath3d, but it is much slower, especially
on the first run.
Value
Called for the side effect of displaying the sprites. The shape ID of the displayed object is returned.
Examples
open3d()
plotmath3d(1:3, 1:3, 1:3, expression(x[1] == 1, x[2] == 2, x[3] == 3))
# This lets the text resize with the plot
text3d(4, 4, 4, "resizeable text", usePlotmath = TRUE, fixedSize = FALSE)
3D plot
# \donttest{
if (requireNamespace("xdvir")) {
# Do the same plot using latex3d(). This example runs slowly!
open3d()
latex3d(1:3, 1:3, 1:3, c("$x_1 = 1$", "$x_2 = 2$", "$x_3 = 3$"))
latex3d(4, 4, 4, "resizeable text", fixedSize = FALSE)
}
#> Loading required namespace: xdvir
#> ! LaTeX Error: File `luatex85.sty' not found.
#>
#> ! Emergency stop.
#> <read *>
#> Error: LaTeX failed to compile file34b9f06701e5d7.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See ./file34b9f06701e5d7.log for more info.
# }