[英]how to plot spherical coordinates in R
how can I plot spherical coordinates(r,theta and phi) in R? 如何在R中绘制球坐标(r,theta和phi)?
is it possible to use the persp()
function? 是否可以使用persp()
函数?
I have a colection of points as well as a grid. 我有一个积分和一个网格。
As long as you know your math , this is a fairly trivial transformation: 只要你知道你的数学 ,这是一个相当微不足道的转变:
spher_to_cart <- function(r, theta, phi) list(x=r*cos(phi)*sin(theta),
y=r*sin(theta)*sin(phi),
z=r*cos(theta))
#An example dataset
data <- data.frame(r=1:10,
theta = seq(0,2*pi,length=10),
phi = seq(2*pi, 0,length=10))
spher_to_cart(data$r, data$theta, data$phi)
$x
[1] 0.000000e+00 9.848078e-01 5.130302e-01 -1.732051e+00 -1.606969e+00 1.928363e+00 3.031089e+00 -1.368081e+00 -4.431635e+00 -2.449294e-15
$y
[1] 0.0000000 -0.8263518 -2.9095389 -3.0000000 -0.5848889 -0.7018667 -5.2500000 -7.7587705 -3.7185832 0.0000000
$z
[1] 1.0000000 1.5320889 0.5209445 -2.0000000 -4.6984631 -5.6381557 -3.5000000 1.3891854 6.8944000 10.0000000
Beware to use values of theta and phi in radians, not degrees. 注意以弧度而不是度数使用theta和phi的值。
Then you can plot using plot3d
for package rgl
for instance: 然后你可以使用plot3d
绘制包rgl
,例如:
s <- spher_to_cart(data$r, data$theta, data$phi)
library(rgl)
plot3d(s$x,s$y,s$z)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.