Home > Enterprise >  Display 2 3D objects preserving their original size ratio
Display 2 3D objects preserving their original size ratio

Time:12-19

Here I have got two 3D objects with the object formed by vertices2 half the size of that formed by vertices. I wish to plot these two objects in rgl window such that smaller one really looks smaller. However, when I tried the following code, I get two EQUALLY SIZED objects. How could I display these two objects with the one on the right proportionally smaller than the one on the left?

library(rgl)
vertices <- c( 
     -1.0, -1.0, 0,
      1.0, -1.0, 0,
      1.0,  1.0, 0,
     -1.0,  1.0, 0
  )
  indices <- c( 1, 2, 3, 4 )
 

 vertices2 <- vertices * 0.5


mfrow3d(1,2,sharedMouse = T)
wire3d( mesh3d(vertices = vertices, quads = indices) )
next3d()
wire3d( mesh3d(vertices = vertices2, quads = indices) )

CodePudding user response:

You are plotting the two objects in independent windows. rgl automatically centers and resizes them to fill the window, so they end up looking the same. The way it does this is by moving the imagined observer closer or further from the scene.

To prevent this, you should set the observer locations to match, e.g.

mfrow3d(1,2,sharedMouse = TRUE)
wire3d( mesh3d(vertices = vertices, quads = indices) )
obs <- par3d("observer")
next3d()
wire3d( mesh3d(vertices = vertices2, quads = indices) )
observer3d(obs)

The observer location is specified using coordinates relative to the center of the bounding box of each scene.

  • Related