Learn R Programming

matlib (version 0.6.0)

vectors3d: Draw 3D vectors

Description

This function draws vectors in a 3D plot, in a way that facilitates constructing vector diagrams. It allows vectors to be specified as rows of a matrix, and can draw labels on the vectors.

Usage

vectors3d(X, origin = c(0, 0, 0), headlength = 0.05, labels = TRUE,
  cex.lab = 1.2, adj.lab = 0.5, frac.lab = 1.1, ...)

Arguments

X
a vector or three-column matrix representing a set of geometric vectors; if a matrix, one vector is drawn for each row
origin
the origin from which they are drawn, a vector of length 3.
headlength
the headlength argument passed to arrows3d determining the length of arrow heads
labels
a logical or a character vector of labels for the vectors. If TRUE and X is a matrix, labels are taken from rownames(X). If NULL, no labels are drawn.
cex.lab
character expansion applied to vector labels. May be a number or numeric vector corresponding to the the rows of X, recycled as necessary.
adj.lab
label position relative to the label point as in text3d, recycled as necessary.
frac.lab
location of label point, as a fraction of the distance between origin and X, recycled as necessary. Values frac.lab > 1 locate the label beyond the end of the vector.
...
other arguments passed on to graphics functions.

Value

  • none

Bugs

At present, the color (col=) argument is not handled as expected.

See Also

arrows3d, code{texts3d} Other vector diagrams: Proj, arrows3d, corner, point_on_line, vectors

Examples

Run this code
vec <- rbind(diag(3), c(1,1,1))
rownames(vec) <- c("X", "Y", "Z", "J")
library(rgl)
open3d()
vectors3d(vec, col=c(rep("black",3), "red"), lwd=2)
# draw the XZ plane, whose equation is Y=0
planes3d(0, 0, 1, 0, col="gray", alpha=0.2)
# show projections of the unit vector J
segments3d(v1 <- rbind(c(1,1,1), c(1, 1, 0)))
segments3d(v2 <- rbind(c(0,0,0), c(1, 1, 0)))
segments3d(v3 <- rbind(c(1,0,0), c(1, 1, 0)))
segments3d(v4 <- rbind(c(0,1,0), c(1, 1, 0)))
rgl.bringtotop()

Run the code above in your browser using DataLab