R scatterplot3d

  • Rで立体を表示したい
  • まずはscatterplot3d()というのがある
  • 球を書いてみた
library(scatterplot3d)
t <- seq(-pi, pi, length = 50)
 x <- c(rep(1, 50) %*% t(cos(t)))
 y <- c(cos(t) %*% t(sin(t)))
 z <- c(sin(t) %*% t(sin(t)))
 scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", col.grid="green", main="ball", pch=20) 
  • (xi,yi,zi)をそれぞれ行列X,Y,Zに押し込むかたちになっているのに注意
  • 媒介変数表示しておいて値を書き出すほうが分かりやすい
  • でも変数を再利用できる
  • パラメータはいろいろある
    • hilight.3d=TRUE : y軸の奥行きを色で表現
    • col.axis = "blue" :軸の色
    • col.grid = "green" : 格子の色
    • main = "ball" : タイトル
    • pch=20 : 点の形状
library(scatterplot3d)
n<-200
t <- seq(0, 8*pi, length = n)
 r<-0.9
 x <- c(r^t*cos(t) %*% t(cos(t)+1))
 y <- c(r^t*sin(t) %*% t(cos(t)+1))
 z <- c(r^t %*% t(sin(t)))+c(2*r^(3*pi)/(1-r^(2*pi))*(1-(r^(2*pi))^(t/(2*pi)-1)))%*%t(rep(1, n))
 scatterplot3d(x, y, z, highlight.3d=TRUE, col.axis="blue", col.grid="green", main="snail", pch=20) 

\begin{bmatrix} r^{\theta}cos\theta(cos\phi+1) \\ r^\theta sin\theta(cos\phi+1) \\ r^\theta sin\phi + \frac{2r^{3\pi}(1-r^{\theta-2\pi})}{1-r^{2\pi}} \end{bmatrix}