# [R] Add axes to a 3D scene (afer makeTriangles)

Christophe Genolini cgenolin at u-paris10.fr
Thu Jan 31 08:50:07 CET 2013

```Hi David,

Here is my (simplified) code :

---- 8< -------------------------
library(misc3d)

#################
### Fonction that draw a point A=(x,y,z), with radius r

misc3dPoint <- function(A,r,color="black",alpha=1){
t1 <- c(A[1]+r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]+r)
t2 <- c(A[1]+r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]-r)
t3 <- c(A[1]+r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]+r)
t4 <- c(A[1]+r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]-r)
t5 <- c(A[1]-r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]+r)
t6 <- c(A[1]-r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]-r)
t7 <- c(A[1]-r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]+r)
t8 <- c(A[1]-r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]-r)
return(data.frame(rbind(t1,t2,t3,t4,t5,t6,t7,t8),color=color,alpha=alpha))
}

#################
### Fonction that draw several points MA=(A,B,C,D,...)

misc3dPoints <- function(MA,r,color="black",alpha=1){
dataV <- data.frame()
if(length(r)==1){r <- rep(r,ncol(MA))}else{}
if(length(color)==1){color <- rep(color,ncol(MA))}else{}
if(length(alpha)==1){alpha <- rep(alpha,ncol(MA))}else{}
for(i in 1:ncol(MA)){
dataV <- rbind(dataV,misc3dPoint(MA[,i],r[i],color=color[i],alpha=alpha[i]))
}
return(dataV)
}

### Some points (points are in colomn)
MA <- cbind(c(3.5,3.5,3.5),c(3,2,1),c(1.5,1,0.5),c(0.3,0.3,0.3),c(0,0,0),c(4,4,4))[3:1,]

### The radius of the points
r = 0.3

### Building the list of triangle3d from the points
listOfTriangles <- misc3dPoints(MA,r,color=c(1:4,1,1),alpha=c(1,1,1,1,0,0))

### Making the scene
myScene <- makeTriangles(
v1=as.matrix(listOfTriangles[,1:3]),
v2=as.matrix(listOfTriangles[,4:6]),
v3=as.matrix(listOfTriangles[,7:9]),
color=listOfTriangles\$color,alpha=listOfTriangles\$alpha
)

### Drawing the scene
drawScene.rgl(myScene,xlim=c(0,4),ylim=c(0,4),zlim=c(0,4))

### Then, I export the triangles into an asy file (with is the final pupose of all this)
library(longitudinalData)
saveTrianglessASY(myScene)

---- 8< -------------------------

So I rewrite my question: is it possible to add some axes to the "myScene" object?

Christophe

>
> On Jan 30, 2013, at 3:09 AM, cgenolin wrote:
>
>> Hi all,
>>
>> I am drawing some 3D surfaces using the Triangle tools (package misc3) and
>> drawScene.rgl. Do you know if it is possible to add axes and graduation on
>> the scene?
>
>
> You offer no code or data,  so a specific answer is not called for. Certainly the specific answer
> to the possibility of labels in rgl graph is is "yes". You might learn something by looking at the
> work that Ben Bolker and I put into a question requesting labels on the scatter3d function in
> package "car";
>
> http://stackoverflow.com/questions/8204972/carscatter3d-in-r-labeling-axis-better/8206320#8206320
>

--
Christophe Genolini
Maître de conférences en bio-statistique
Vice président Communication interne et animation du campus
Université Paris Ouest Nanterre La Défense

```