如何在 R 中绘制 3d 参数方程?
来自维基页面上的参数方程(http://en.wikipedia.org/wiki/Parametric_equation ),我可以绘制二维方程如下:
From the parametric equations on wiki page ( http://en.wikipedia.org/wiki/Parametric_equation ), I can plot 2d equations as follows:
#for a circle:
x = seq(-pi, pi, length.out=30)
plot(sin(x),cos(x))
# for a star:
a=10; b=10/1.8
x=seq(-50,50,length.out=500)
plot((a-b)*cos(x)+b*cos(x*((a/b)-1)), (a-b)*sin(x)-b*sin(x*((a/b)-1)), ylim=range(-13,13))
如何在方程给出的螺旋的 3d 图上绘制 3d 方程:
How can I plot 3d equations on a 3d plot of a Helix given by equations:
x=a*cos(t)
y=a*sin(t)
z=b*t
通过搜索,我发现 3d 绘图函数采用矩阵或 x、y、z 值,但不采用数学曲线函数.
From searching I found that the 3d plotting functions take either a matrix or x,y,z values but not math curve functions.
您可以像绘制 2D 方程一样绘制 3D 方程.
You can plot 3D equations like you did the 2D ones.
library(lattice)
t<-seq(-2*pi, 2*pi, length.out=200)
cloud(z~x+y,data.frame(x=3*cos(t),y=3*sin(t), z=2*t))
所以是的,您不能直接提供原始函数,但您可以根据这些函数轻松计算要绘制的点.如果您有其他想法,请告诉我.
So yes, you can't supply a raw function directly, but you can easily calculate points to plot based on those functions. Let me know if you had something else in mind.
这是一个两参数的圆环
t <- seq(0, 2*pi, length.out=50);
u <- seq(0, 2*pi, length.out=50);
tu<-expand.grid(t=t,u=u)
R <- 6;
r <- 3;
tu <- transform(tu,
x = cos(t)*(R+r*cos(u)),
y = sin(t)*(R+r*cos(u)),
z = r*sin(u)
)
rr<-c(-10,10)
cloud(z~x+y, tu, xlim=rr, ylim=rr, zlim=rr, screen=list(y=20));
实际上,我刚刚意识到 wireframe
更好,只是花了我一点时间来弄清楚语法.
Actually, I just realized wireframe
is better, just took me a bit longer to figure out the syntax.
xm<-outer(t,u,function(t, u)cos(t)*(R+r*cos(u)))
ym<-outer(t,u,function(t, u)sin(t)*(R+r*cos(u)))
zm<-outer(t,u,function(t, u) r*sin(u))
rr<-c(-10,10)
wireframe(zm~xm+ym, xlim=rr, ylim=rr, zlim=rr, screen=list(y=30))
在 ?cloud
帮助页面上可以找到更多详细信息
More details found on the ?cloud
help page