File: aspect3d.R

package info (click to toggle)
rgl 1.3.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,968 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 6,125; sh: 3,555; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
aspect3d <- function(x, y = NULL, z = NULL) {
    if (is.character(x) && pmatch(x, "iso") == 1) {
    	scale <- c(1,1,1)
    } else {
	if (is.null(y)) {
	    x <- rep(x, length.out = 3)
	    z <- x[3]
	    y <- x[2]
	    x <- x[1]
	}
        for (i in 1:5) { # To handle spheres, repeat this 
  	    bbox <- .getRanges()
	    scale <- c(diff(bbox$xlim), diff(bbox$ylim), diff(bbox$zlim))
	    scale <- ifelse(scale <= 0, 1, scale)

	    avgscale <- sqrt(sum(scale^2)/3)
            scale <- c(x,y,z)*avgscale/scale
            oldscale <- par3d(scale = scale)$scale
            if (isTRUE(all.equal(scale, oldscale)))
            	break
        }
    }
    par3d(scale = scale)
}