trans3D: Transformation of 3D elements

Description Usage Arguments Value Author(s) See Also Examples

View source: R/functions.R

Description

trans3D is the plot3D equivalent of trans3d, that projects 3-D elements to 2 dimensions.

Usage

1
trans3D (x, y, z, pmat) 

Arguments

x, y, z

Vectors, matrices, arrays, with x, y and z-values.

pmat

A 4 x 4 viewing transformation matrix, suitable for projecting the 3D coordinates (x,y,z) into the 2D plane using homogeneous 4D coordinates (x,y,z,t); such matrices are returned by any of the 3-D plotting functions from package plot3D and by persp().

Value

A list with two components:

In contrast to trans3d, trans3D the returned values x and y will be of the same class and dimensions as the input x and y. If inputted x, y, z are matrices or arrays, so will the projected coordinates be.

Author(s)

Karline Soetaert <karline.soetaert@nioz.nl>

See Also

scatter3D, slice3D, surf3D.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## ========================================================================
## 3-D mesh
## ========================================================================

 x <- y <- z <- c(-1 , 0, 1)

# plot a 3-D mesh
 (M <- mesh(x, y, z))

# plot result
 pmat <- scatter3D(M$x, M$y, M$z, pch = "+", cex = 3, colkey = FALSE)

# add line
 XY <- trans3D(x = c(-1, 1), y = c(-1, 1), z = c(-1, 1), pmat = pmat) 
 lines(XY, lwd = 2, col = "blue")

## ========================================================================
## Example 2
## ========================================================================

 pmat <- perspbox (z = diag(2))
 XY <- trans3D(x = runif(30), y = runif(30), z = runif(30), pmat = pmat) 
 polygon(XY, col = "darkblue")

Example output

$x
, , 1

     [,1] [,2] [,3]
[1,]   -1   -1   -1
[2,]    0    0    0
[3,]    1    1    1

, , 2

     [,1] [,2] [,3]
[1,]   -1   -1   -1
[2,]    0    0    0
[3,]    1    1    1

, , 3

     [,1] [,2] [,3]
[1,]   -1   -1   -1
[2,]    0    0    0
[3,]    1    1    1


$y
, , 1

     [,1] [,2] [,3]
[1,]   -1    0    1
[2,]   -1    0    1
[3,]   -1    0    1

, , 2

     [,1] [,2] [,3]
[1,]   -1    0    1
[2,]   -1    0    1
[3,]   -1    0    1

, , 3

     [,1] [,2] [,3]
[1,]   -1    0    1
[2,]   -1    0    1
[3,]   -1    0    1


$z
, , 1

     [,1] [,2] [,3]
[1,]   -1   -1   -1
[2,]   -1   -1   -1
[3,]   -1   -1   -1

, , 2

     [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0
[3,]    0    0    0

, , 3

     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    1    1    1
[3,]    1    1    1

plot3D documentation built on May 22, 2021, 5:06 p.m.

Related to trans3D in plot3D...