-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrain.r
More file actions
executable file
·48 lines (40 loc) · 1.66 KB
/
strain.r
File metadata and controls
executable file
·48 lines (40 loc) · 1.66 KB
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
#!/usr/bin/env Rscript
#LOAD LIbrary
library(rgl)
dir.create("strain")
par3d(windowRect = c(0, 50, 800, 800),
userMatrix = rotationMatrix(-30*pi/180, 0, 1, 0.5) %*% par3d("userMatrix"))
totalFrames <- 20
for (frame in 1:totalFrames) {
plot3d(0.05, 0.05, 0.05,
col = "white",
xlab="", ylab="", zlab="",
xlim=c(-0.2,0.6),
ylim=c(-0.2,0.6),
zlim=c(-0.2,0.6),
axes = FALSE)
c3d <- cube3d()
A <- matrix(c(0.15,0,0,0,0.15,0,0,0,0.15),3,3)
c3d <- transform3d(c3d, A)
a <- 1 + frame*0.005
b <- frame*0.005
c <- frame*0.005
d <- frame*0.005
e <- 1 + frame*0.005
f <- frame*0.005
g <- frame*0.005
h <- frame*0.005
i <- 1 + frame*0.005
A <- matrix(c(a,b,c,d,e,f,g,h,i),3,3)
c3d_trans <- transform3d(c3d, A)
for (i in 1:6)
lines3d(t(c3d_trans$vb)[c3d$ib[,i],])
newFrame <- totalFrames*2 - frame
rgl.postscript(filename=paste("strain/strain-",sprintf("%03d",frame), ".pdf", sep=""), fmt="pdf")
system(paste("convert -crop 400x400+75+285 +repage -sharpen 0x1.0 -quality 100 strain/strain-",sprintf("%03d", frame), ".pdf strain/strain-",sprintf("%03d", frame), ".pdf", sep=""))
system(paste("convert -sharpen 0x1.0 -quality 100 strain/strain-",sprintf("%03d", frame), ".pdf strain/strain-",sprintf("%03d", frame), ".png", sep=""))
if (frame != newFrame)
file.copy(paste("strain/strain-",sprintf("%03d", frame),".png", sep=""), paste("strain/strain-", sprintf("%03d", newFrame), ".png", sep=""), overwrite = TRUE)
clear3d()
}
system(paste("convert -dispose previous -delay 1 -quality 100 strain/*.png strain/strain.gif", sep=""))