```source("http://macosa.dima.unige.it/r.R")    # If I have not already loaded the library

[ Vedi qui ]

---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

# SELECT everything (from here to ###) and paste in R

# We use co[] for the colors of the various parts of the image

co=NULL
co[1]="grey30"
co[2]="blue"
co[3:6]="black"
co[7]="white"
co[8]="white"
co[9]="black"
co[10]="black"
co[11]="brown"
co[12]="white"
co[13]="brown"
co[14]="brown"
co[15]="black"

x = c(-0.1,5); y = c(-0.1,3); w = c(-0.1,3)        # the box
z = array(c(w[1],w[1],w[1],w[1]), dim=c(2,2))            # z-coord. of the base of the box
# I trace the box, choose a point of view with th and ph (direction of look projected on
# horizontal plane, its inclination relative to that plane); scale=FALSE  chooses a
# monometric scale; di chooses the distance of the eye

thphdi = function(t,p,di) {
par( mai = c(0,0,0,0) )          # I reduce the margins
F = persp(x,y,z,theta=t,phi=p,scale=FALSE,zlim=w,xlim=x,ylim=y,d=di,box=FALSE,border="white")
FFF <<- F
xm=5; ym=3; zm=3
# grid  (z=0 plane, x=0 plane, y=0 plane)
if(co[1]!="white") for(i in seq(1,xm,1)) lines(trans3d(i,c(0,ym),0,pmat=F),col=co[1],lty=3)
if(co[1]!="white") for(i in seq(1,ym,1)) lines(trans3d(c(0,xm),i,0,pmat=F),col=co[1],lty=3)
if(co[1]!="white") for(i in seq(1,ym,1)) lines(trans3d(0,i,c(0,zm),pmat=F),col=co[1],lty=3)
if(co[1]!="white") for(i in seq(1,zm,1)) lines(trans3d(0,c(0,ym),i,pmat=F),col=co[1],lty=3)
if(co[1]!="white") for(i in seq(1,xm,1)) lines(trans3d(i,0,c(0,zm),pmat=F),col=co[1],lty=3)
if(co[1]!="white") for(i in seq(1,zm,1)) lines(trans3d(c(0,xm),0,i,pmat=F),col=co[1],lty=3)
# axes
if(co[2]!="white") lines(trans3d(c(0,0),c(0,0),c(0,zm),pmat=F),col=co[2],lty=3)
if(co[2]!="white") lines(trans3d(c(0,xm),c(0,0),c(0,0),pmat=F),col=co[2],lty=3)
if(co[2]!="white") lines(trans3d(c(0,0),c(0,ym),c(0,0),pmat=F),col=co[2],lty=3)
# figure (top)
if(co[3]!="white") lines(trans3d(c(2,2),c(1,2),c(1,1),pmat=F),col=co[3])
if(co[4]!="white") lines(trans3d(c(2,4),c(1,1),c(1,1),pmat=F),col=co[4])
if(co[5]!="white") lines(trans3d(c(4,4),c(1,2),c(1,1),pmat=F),col=co[5])
if(co[6]!="white") lines(trans3d(c(2,4),c(2,2),c(1,1),pmat=F),col=co[6])
# figure (bottom)
if(co[7]!="white") lines(trans3d(c(2,2),c(1,2),c(0,0),pmat=F),col=co[7])
if(co[8]!="white") lines(trans3d(c(2,4),c(1,1),c(0,0),pmat=F),col=co[8])
if(co[9]!="white") lines(trans3d(c(4,4),c(1,2),c(0,0),pmat=F),col=co[9])
if(co[10]!="white") lines(trans3d(c(2,4),c(2,2),c(0,0),pmat=F),col=co[10])
# figure (side)
if(co[11]!="white") lines(trans3d(c(4,4),c(1,1),c(0,1),pmat=F),col=co[11])
if(co[12]!="white") lines(trans3d(c(2,2),c(1,1),c(0,1),pmat=F),col=co[12])
if(co[13]!="white") lines(trans3d(c(2,2),c(2,2),c(0,1),pmat=F),col=co[13])
if(co[14]!="white") lines(trans3d(c(4,4),c(2,2),c(0,1),pmat=F),col=co[14])
# man
if(co[15]!="white") lines(trans3d(0,2,c(0,2),pmat=F),lwd=3,col=co[2])
if(co[1]!="white") points(trans3d(0,2,2,pmat=F),pch=19,col=co[15])
}
###
BF=3; HF=3; NW(); thphdi(130,25,1)
#
W = PXY(c(2,4,4,2),c(1,1,2,2),c(1,1,1,1),FFF); X=W[1:4]; Y=W[5:8]; polygon(X,Y,col="orange")
W = PXY(c(4,4,4,4),c(1,2,2,1),c(0,0,1,1),FFF); X=W[1:4]; Y=W[5:8]; polygon(X,Y,col="orange")
W = PXY(c(2,4,4,2),c(2,2,2,2),c(0,0,1,1),FFF); X=W[1:4]; Y=W[5:8]; polygon(X,Y,col="orange")

```