Well I've figures out a painful way of doing it with triangles 3d, as
suggested in another post by Duncan Murdoch.
The code is disgusting, but it works.
x <- c(0,0.75,75.75,150.75,225.75,300.75,375.75,450.75,525.75,600.75,675.75,
675.75,0,
0,0.5,50.5,100.5,150.5,200.5,250.5,300.5,350.5,400.5,450.5, 450.5,0,
0,0.25,25.25,50.25,75.25,100.25,125.25,150.25,175.25,200.25,225.25,225.25,0)
y <- c(0,0.05,4.91,9.78,14.64,19.51,24.38,29.24,34.11,38.97,43.84, 43.84,0,
0,0.1,9.83,19.56,29.29,39.02,48.75,58.48,68.21,77.94,87.67, 87.67,0,
0,0.15,14.74,29.34,43.93,58.53,73.13,87.72,102.32,116.91,131.51,
131.51,0)
z <- c(0,0.05,0.55,0.7,0.78,0.83,0.87,0.9,0.92,0.93,0.94,0.0,0,
0,0.32,0.59,0.77,0.87,0.93,0.96,0.98,0.99,1,0,0,0,
0,0.39,0.66,0.82,0.9,0.95,0.97,0.99,0.99,1,0,0,0)
dat <- data.frame(x = x, y = y, z = z, ID = c(rep(c(1,2,3),each=13)))
x1 <- x[1:13]
y1 <- y[1:13]
z1 <- z[1:13]
x2 <- x[14:26]
y2 <- y[14:26]
z2 <- z[14:26]
x3 <- x[27:39]
y3 <- y[27:39]
z3 <- z[27:39]
t1 <- triangulate(as(cbind(x1,z1), "gpc.poly"))
t2 <- triangulate(as(cbind(x2,z2), "gpc.poly"))
t3 <- triangulate(as(cbind(x3,z3), "gpc.poly"))
yfit1 <- predict(lm(y1~ x1 + z1), newdata = data.frame(x1 = t1[,1], z1
t1[,2]))
yfit2 <- predict(lm(y2~ x2 + z2), newdata = data.frame(x2 = t2[,1], z2
t2[,2]))
yfit3 <- predict(lm(y3~ x3 + z3), newdata = data.frame(x3 = t3[,1], z3
t3[,2]))
plot3d(dat, type = "n", ylab = "", xlab = "", zlab
= "", axes = F, ylim c(0,200))
axes3d(edge = c("x--", "y-+", "z--"), nticks = 5,
ylim = c(0,200))
bbox3d(color = c("black", "white"), lit = F, back =
"line")
lines3d(x1, y1, z1)
lines3d(x2, y2, z2)
lines3d(x3, y3, z3)
triangles3d(x= t1[,1], y= yfit1, z= t1[,2], lit = F, col = "white",
front "fill", lwd = 10)
triangles3d(x= t2[,1], y= yfit2, z= t2[,2], lit = F, col = "white",
front "fill", lwd = 10)
triangles3d(x= t3[,1], y= yfit3, z= t3[,2], lit = F, col = "white",
front "fill", lwd = 10)
PatGauthier wrote>
>
> I'm trying to simply fill in the area under a curve using RGL.
Here' the
> set up:
>
> ........
>
> Any ideas/tips on how to do this?
>
>
PatGauthier wrote>
> Dear useRs,
>
> I'm trying to simply fill in the area under a curve using RGL.
Here' the
> set up:
>
> x <-
c(0.75,75.75,150.75,225.75,300.75,375.75,450.75,525.75,600.75,675.75,
> 0.5,50.5,100.5,150.5,200.5,250.5,300.5,350.5,400.5,450.5,
> 0.25,25.25,50.25,75.25,100.25,125.25,150.25,175.25,200.25,225.25)
> y <- c(0.05,4.91,9.78,14.64,19.51,24.38,29.24,34.11,38.97,43.84,
> 0.1,9.83,19.56,29.29,39.02,48.75,58.48,68.21,77.94,87.67,
> 0.15,14.74,29.34,43.93,58.53,73.13,87.72,102.32,116.91,131.51)
> z <- c(0.05,0.55,0.7,0.78,0.83,0.87,0.9,0.92,0.93,0.94,
> 0,0.32,0.59,0.77,0.87,0.93,0.96,0.98,0.99,1,
> 0,0.39,0.66,0.82,0.9,0.95,0.97,0.99,0.99,1)
>
> dat <- data.frame(x = x, y = y, z = z, ID = c(rep(c(1,2,3),each=10)))
>
> plot3d(dat, type = "n", ylab = "", xlab = "",
zlab = "", axes = F, ylim > c(0,200))
> lines3d(dat[1:10,])
> lines3d(dat[11:20,])
> lines3d(dat[21:30,])
>
> axes3d(edge = c("x--", "y-+", "z--"), nticks
= 5, ylim = c(0,200))
> bbox3d(color = c("black", "white"), lit = F, back =
"line")
>
> Any ideas/tips on how to do this?
>
> thanks in advance,
>
> Patrick
>
--
View this message in context:
http://r.789695.n4.nabble.com/RGL-3D-curvilinear-shapes-tp4636011p4636057.html
Sent from the R help mailing list archive at Nabble.com.