args3d: Process 3D arguments

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

Description

Process 3D arguments, also allowing xy, xz, yz to indicate planes in 3D space, and allowing, e.g., x='min', x='max', x='mid' to specify the minimum, maximum, or middle value for a given coordinate axis.

Usage

1

Arguments

...

A collection of arguments for 3D graphics functions including x, y, z

Details

For any coordinate axis or plane you can specify 'min', 'max', 'mid' as values

Value

Returns a list with a matrix, x with xyz values and with other arguments specified in the call.

Note

If the first argument is positional then variables must be in order x,y,z

Author(s)

Georges Monette

See Also

Plot3d, Lines3d,

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(...) {
help <- "

    - returns a list with a matrix, x with xyz values and with other args
    - can specify 'min', 'max', 'mid' as values not mixed with numerical
      values
    CAUTION: If first argument is positional then variables
             must be in order x,y,z
"
    na2f <- function( x ) {
         x[is.na(x)] <- FALSE
         x
    }
    args <- list(...)
    
    getdim <- function(nam, args){
        pos <- regexpr(nam, names(args)) 
        arg.ind <- pos > 0
        if( length(pos <- pos [ pos > 0 ])==0) return(0)
        cbind( args[arg.ind][[1]])[,pos]
    }
    
    if( is.null(names(args))) names(args) <- rep("",length(args) )
    nn <- names(args)
		#disp(nn)
        if ( (length(nn) >2) && all( nn[1:3] =="")) names(args) [1:3] <- c('x','y','z')
        nn <- names(args)
        if ( (length(nn) > 0) && (nn[1] == "") ){
						 names(args)[1] <- 'xyz'
						 args[[1]] = rbind( args[[1]])	
				}
        nn <- names(args)
        #disp(nn)
    nxyz <- sapply( nn, regexpr, "xyzyxzxzyyzxzxyzyz")
    #disp(nxyz)

    xyzs <- args[nxyz > 0]
    #disp(xyzs)
    oargs <- args[nxyz < 0]
    #disp(oargs)
		xyz <- cbind( x=getdim('x', xyzs), y=getdim('y',xyzs), z=getdim('z',xyzs))
    if ( is.character(xyz) ) {
        bbox <- par3d('bbox')
        mins <- matrix(bbox[c(1,3,5)], nrow = nrow(xyz), ncol=3, byrow = T)
        maxs <- matrix(bbox[1+c(1,3,5)], nrow = nrow(xyz), ncol=3, byrow = T)
        mids <- (mins + maxs)/2
        xyz[na2f(xyz=='min')] <- mins[na2f(xyz=='min')]
        xyz[na2f(xyz=='max')] <- maxs[na2f(xyz=='max')]
        xyz[na2f(xyz=='mid')] <- mids[na2f(xyz=='mid')]
        mode(xyz) <- "numeric"
    }
    a <- list(x = xyz)
    c(a,oargs)
  }


Search within the p3d package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.