2017-12-08 5 views
2

큐브 내에서 직각 프리즘을 만들려고합니다. 큐브가 1x1x1 단위의 차원을 가지며 0,0,0을 원점으로합니다. 큐브 내의 직사각형은 원점에서 시작하여 이상적으로 벡터 변수에서 가져와 XYZ 치수를 가져옵니다. 직각 프리즘은 0에서 1까지의 양수 값만 가질 수 있습니다.이 때문에 기수 주변의 모든 치수에서 -1에서 1을 표시하는 cube3d의 기본값 인 것처럼 양수 값을 표시하려고합니다.rgl 패키지 - 큐브 내의 큐브

이 작업을 수행하는 방법에 관해 누군가가 올바른 방향으로 나를 가리킬 수 있습니까?

데이터 예 :

Augusta = c(0.4, 0.2, 0.8) 

나는 현재 (유래에서 가져온) 한 코드 -

c3d <- cube3d(color="red", alpha=0.5) 
c3d 
shade3d(c3d) 
axes3d() 
rgl.viewpoint(theta = 45, phi = 25, fov = 60, zoom = 1) 

가 내 요구에 맞게이 기능을 적용 할 수 있습니까? 그렇다면 방법은 어떻게 생겼을까요? 이것이 올바른 기능이 아니라면 무엇을 제안하겠습니까?

다른 입력을 필요로하기 때문에 선호되지 않을 것이다 내가 찾은 또 다른 잠재적 인 방법은, 그러나, 나는 당신의 문제를 이해 할 수 있는지 모르겠지만, 아마도 scale3d()translate3d() 줄 것 here

답변

0
#Data example 
Nominal_City_Name = c(0.7,0.2,0.5) 
X = Nominal_City_Name[1] 
Y = Nominal_City_Name[2] 
Z = Nominal_City_Name[3] 

#Bring in RGL library 
library(rgl) 

#Contributor cuttlefish44's code 
c3d <- cube3d(color="grey", alpha=0.1) 
c3d2 <- c3d %>% 
    translate3d(1, 1, 1) %>% 
    scale3d(0.5, 0.5, 0.5) 

c3d3 <- cube3d(color = "blue", alpha = (0.5)) %>% 
    translate3d(1, 1, 1) %>% 
    scale3d(0.5, 0.5, 0.5) %>% 
    scale3d(X, Z, Y) 

shade3d(c3d2) 
shade3d(c3d3) 
axes3d() 
# Add points at vertices 
points3d(t(c3d3$vb), size = 5) 
# Add lines to edges of box 
for (i in 1:6) lines3d(t(c3d3$vb)[c3d3$ib[,i],]) 

#------------Add labels/title to 3d window------- 
# This version of title (commented out) doesn't work as well as the 
# bgplot3d() version now included in output section below. 
# Use this title3d() version if you want the title to be dynamic to 
# the graphic.  

#Title_XYZ = paste0(stakeholder," ","X, Y, Z") 
#title3d(main =Title_XYZ,cex = 2, line = 2) 

mtext3d("X Var",edge="x-+",line=2,las=2,cex=2,srt = 50,col = 
      "darkorange3") 
mtext3d("Y Var",edge="z+-",line=2.5,las=2,cex=2, col = 
      "chartreuse4", srt = 90) 
mtext3d("Z Var",edge="y-+",line=3,las=2,cex=2, col = 
      "darkblue") 

# 
#-------Create output file------- 
#This section first sets the window view parameters and window size 
# to what I want it to be. Then it exports to a location you choose. 

# After dynamically moving it to look the way you want in 3d view - 
# Use par3d() to get view attributes (i.e., windowRect (window size) 
# info), among other measurements. Theta, phi, fov, and zoom give 
# angles, field of vision, and zoom. 

rgl.viewpoint(theta = 45, phi = 4, fov = 60, zoom = 1) 
window_size = c(164,32,1259,1050) 
par3d(windowRect = window_size) 

#Adding title using a background plot. This must be done AFTER 
#resizing the window, because it doesn't scale gracefully. 
Title_XYZ = "This is your title" 
bgplot3d(
    plot.new() + 
    title(main = Title_XYZ, line = -10,cex.main=3)) 

     #a = folder, b = stakeholder name, c = file extension, d = concat  of 
    #all 3 for export 
    # a = "C:\\Users\\MyUserName\\Documents\\R\\export" 
    # b = Title_XYZ 
    # c=".jpg" 
    # d = paste0(a,b,c) 
    # rgl.snapshot(d) 
+0

제목을 어디에 넣으시겠습니까? 장면과 함께 움직이기 원하면'mtext3d'를 사용하십시오; 그렇지 않으면, 당신은'bgplot3d'를 사용하여 배경에 그것을 쓸 수 있고, view를'layout3d' 예제와 같이 움직이고 움직이지 않는 부분으로 나눌 수 있습니다. – user2554330

+0

안녕하세요 사용자 - 제안 해 주셔서 감사합니다. bgplot3d는 큰 성과를 냈습니다! 완성 된 답변에 이것을 추가하십시오. – jrcook1106

+0

'plot.new() + title (...)'을 사용하지 않겠습니다. 여기서는 (두 함수 모두'NULL'을 반환하지만) 다른 경우에는 추가 할 수없는 것을 추가하려고 시도 할 때 경고 나 오류가 발생할 수 있습니다. '{plot.new(); 제목 (...)}'(또는 두 줄에 같은 것, 세미콜론 필요 없음). – user2554330

1

를 설명 원하는 것 (?scale3d 참조).

library(rgl) 

c3d <- cube3d(color="red", alpha=0.5) 
c3d2 <- c3d %>% 
    translate3d(1, 1, 1) %>% 
    scale3d(0.5, 0.5, 0.5) 

c3d3 <- cube3d(color = "blue") %>% 
    translate3d(1, 1, 1) %>% 
    scale3d(0.5, 0.5, 0.5) %>% 
    scale3d(0.4, 0.2, 0.8) 

shade3d(c3d2) 
shade3d(c3d3) 
axes3d() 
# title3d(xlab = "x", ylab = "y", zlab = "z") 

enter image description here

+0

감사합니다! 이것은 잘 작동합니다. 당신이 나를 다시 썼을 때 scale3d 함수를 찾았지만 올바르게 작동하게하는 방법을 찾지 못했습니다. %> %는 또한 굉장합니다. 나는 그 중 어느 것이 존재하는지 전혀 몰랐습니다. 확실히 시간/공간 보호기! – jrcook1106

+0

코드의 "최종 버전"을 얻으면 그에 대한 응답을하겠습니다. 다시 한 번 감사드립니다 – jrcook1106

+0

'library (dplyr)'문을 없앨 수 있습니다; 그 패키지에서 아무 것도 사용하지 마십시오. – user2554330