I have some trouble with generating .png from each rows of data frame.
Basically, I want to rbind
each one of the row of df
to coordinate_sys
.
For each row of df
together with coordinate_sys
, a coordinate system and one a unit vector "J" should be generated like in this
Finally, after generating a .png file for each unit_vector, I would like to make .gif animation.
here is the reproducible code of my script;
library(matlib)
library(rgl)
set.seed(12)
x <- runif(10,-0.14,0.1)
y <- runif(10,-0.14,0.1)
z <-sort(runif(10,-0.9,0.9),decreasing=TRUE)
df <- data.frame(x,y,z)
rot <- function(df,out){
coordinate_sys <- rbind(c(1,0,0),c(0,-1,0),c(0,0,1))
vec <- rbind(coordinate_sys, unlist(df))
rownames(vec) <- c("X", "Y", "Z", "J")
print(vectors3d(vec, col=c(rep("black",3), "red"), lwd=2))
out <- png(file="example%02d.png", width=200, height=200)
dev.off()
}
apply(df, 1,rot,out)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…