mesh3d: Draw a 3D-mesh

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

mesh3d visualizes 3D meshes and parametric functions in the VRML- or Livegraphics3D-format.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
mesh3d(xfun = "sin(v)*cos(u)", yfun = "sin(v)*sin(u)",
       zfun = "cos(v)", param1 = "u", param2 = "v",
       range1 = c(0, 2 * pi), range2 = c(0, pi),
       size1 = 30, size2 = 30, type = "vrml", x = NULL,
       y = NULL, z = NULL, edges = NULL, obj_infile = NULL,
       filename = "out.wrl", write_obj = FALSE, cols = "red",
       scalefac = 4, autoscale = ifelse(is.null(obj_infile),
       "independent", "equicenter"), 
       lab.axis = c("X-axis", "Y-axis", "Z-axis"),
       col.axis = "black", showaxis = TRUE, col.lab = "black",
       col.bg = "white", cex.lab = 1, htmlout = NULL,
       hwidth = 1200, hheight = 800,
       vrml_navigation = "EXAMINE", vrml_transparency = 0,
       vrml_fov = 0.785, vrml_pos = rep(scalefac + 4, 3),
       vrml_dir = c(0.19, 0.45, 0.87, 2.45),
       lg3d_ambientlight = 0.5)

Arguments

xfun

parametric function to define curves and surfaces (1. dimension)

yfun

parametric function to define curves and surfaces (2. dimension)

zfun

parametric function to define curves and surfaces (3. dimension)

param1

name of the first parameter used in parametric functions

param2

name of the second parameter used in parametric functions

range1

value range for parameter "param1"

range2

value range for parameter "param2"

size1

mesh size for the first parameter used in parametric functions

size2

mesh size for the second parameter used in parametric functions

type

the output type ("vrml" or "lg3d"), this will be set automatically if mesh3d is called after vrml.open() or lg3d.open()

x

a 3-column numeric matrix of coordinates or a numeric vector of x-coordinates (not used if parameter obj\_infile or xfun is specified)

y

a numeric vector of y-coordinates (only needed if x is a vector)

z

a numeric vector of z-coordinates (only needed if x is a vector)

edges

a numerical matrix in which each row contains a sequence of vertex identifiers representing the edges of a polygonal face (vertex identifiers are integer numbers, starting with 0)

obj_infile

filename of a 3D mesh input file in obj-format (not required if edges and x,y,z or the parameters for parametric functions are specified)

filename

filename of the generated output file

write_obj

TRUE, if the output is to be created in the obj-format (requires parameters x,y,z and edges to be set)

cols

the color of the output

scalefac

a numerical scaling factor to increase/decrease the size of the plotted 3D objects

autoscale

the scaling type. "independent" means all axes are auto-scaled independently. "equidist" means all axes are scaled by the same factor and "equicenter" additionally positions the drawn object in the center. "none" means no scaling is applied

lab.axis

a vector of size 3 containing the axis labels

col.axis

color of the axis

showaxis

if FALSE, the coordinate axes are hidden in the output

col.lab

a vector of colors specifying the axis labels

col.bg

background color

cex.lab

scaling factor for axis label font size

htmlout

a filename for generating an HTML-file to embed the output

hwidth

width of the embedded visualization in the HTML-output

hheight

height of the embedded visualization in the HTML-output

vrml_navigation

type of mouse navigation in the VRML file, can be "EXAMINE", "WALK", "SLIDE", "FLY" or "PAN" (VRML only)

vrml_transparency

a number between 0 and 1 specifying the transparency level of plotted objects (VRML only)

vrml_fov

a scalar defining the field of view angle in the VRML file in radians (VRML only)

vrml_pos

a vector of size 3 corresponding to the position of the viewpoint (VRML only)

vrml_dir

a vector of size 4 specifying the viewing direction (first 3 components) and the rotation of the camera around the direction vector (last component in radians, VRML only)

lg3d_ambientlight

ambient light gray level (value between 0 and 1, LG3D only)

Details

mesh3d visualizes 3D-curves and surfaces specified as parametric functions as well 3D-meshes defined by vertex-coordinates and edges between them. The output can be generated in the VRML- or Livegraphics3D-format, or in the obj-format, if the x,y,z- and edges-parameters are specified. There are three ways to provide 3D data as input: An obj-file in the current directory can be used as by setting the obj\_infile-parameter, a 3D mesh can be specified using the x,y,z and edges parameter (in both cases, no other parameters are required), or a parametric function can be defined using the xfun, yfun and zfun parameters (in this case, param1, param2, range1 and range2 parameters have to be set additionally).

To add additional shapes and objects to the final 3D scene, this plotting function can also be called within a VRML- or Livegraphics3D-environment created by calling the vrml.open() or lg3d.open() function. In this case, mesh3d will inherit all global parameters set in the vrml.open- or lg3d.open- function (e.g. filename, type, htmlout, etc.) and the user does not need to specify these options anymore.

Value

The function is used for its side-effect (creating a VRML-, Livegraphics3D-, or obj-file) and has no return value.

Author(s)

Enrico Glaab

References

Enrico Glaab, Jonathan M. Garibaldi, Natalio Krasnogor (2010). vrmlgen: An R Package for 3D Data Visualization on the Web. Journal of Statistical Software, 36(8), p. 1-18. URL: http://www.jstatsoft.org/v36/i08/

See Also

cloud3d, bar3d

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
curdir <- getwd()
outdir <- tempdir()
setwd(outdir)

# Visualization of a parametric function
# defining the surface of 3D spiral

mesh3d(xfun = "s * cos(s) * (4 + cos(t + s))",
       yfun = "s * sin(s) * (4 + cos(t + s))",
       zfun = "s * sin(t + s)", param1 = "s",
       param2 = "t",range1 = c(0, 4 * pi),
       range2 = c(0, 2 * pi), type = "vrml",
       filename = "spiral.wrl",
       htmlout = "spiral.html")
       
# show the output in a web-browser 
# (VRML-plugin must be installed!)
if(file.exists(paste("file://",file.path(outdir,
                "spiral.html"), sep = "")))
{                
  browseURL(paste("file://",file.path(outdir,
                  "spiral.html"), sep = ""))
}

setwd(curdir)

vrmlgen documentation built on May 2, 2019, 1:06 p.m.