2017-07-30 89 views
0

我可以通過RGL場景沿三個軸中的任何一個移動平面(例如,請參見下面的示例),但是如何沿平面對角線移動平面(沿着對角線移動垂直於平面,如果平面不垂直於軸線)?另外,碰到包圍盒會導致問題?我不知道vertexControl是否可能,但我也不知道如何用ageControl來做到這一點。用rgl對角線移動平面

library(rgl) 
xyz <- matrix(rnorm(300), ncol = 3) 
plotid <- plot3d(xyz) 
planeid <- planes3d(0, 0, 1, 0, col = "blue") 
r <- c(-3,3) 
widge = rglwidget() %>% 
playwidget(vertexControl(values = matrix(r, 2, 6), 
    vertices = 1:6, attributes = "z", objid = planeid, param = r), 
    start = r[1], stop = r[2], step = 0.1, precision = 2, 
    components = c("Play", "Slider", "Label")) 
htmltools::save_html(widge, "Rtemporary/Example1.html") 

回答

1

這並不容易。平面存儲爲4個三角形(因爲平面與邊界框相交時可以顯示爲六邊形)。您需要計算每個想要的值的對角線平面與邊界框的交點,然後適當更新三角形。

將這些計算推到Javascript中會更有意義,因此只需存儲平面的原始參數(a,b,c,d),然後就可以直接操縱它們。也許有一天rgl會做到這一點。

修改添加:實際上,rgl已經在Javascript中做了三角測量計算,但vertexControl不知道如何要求它改變平面參數。從版本0.98.12開始(目前僅在R-forge上可用,即將在Github的鏡像中,有一天在CRAN上)它就可以。

你會使用適當a,b,c,d參數 得到你想要的角度指定平面,然後調用vertexControl與參數values = r, vertices = 1, attributes = "offset"改變d設置爲平面。你的榜樣應該是這樣的:

library(rgl) 
xyz <- matrix(rnorm(300), ncol = 3) 
plotid <- plot3d(xyz) 
planeid <- planes3d(1, 1, 1, 0, col = "blue") 
r <- c(-3,3) 
rglwidget() %>% 
    playwidget(vertexControl(values = r, 
       vertices = 1, attributes = "offset", objid = planeid, param = r), 
      start = r[1], stop = r[2], step = 0.1, precision = 2, 
      components = c("Play", "Slider", "Label")) 

(。無需爲save_html東西,當你打印的小工具,自動發生)