[英]How to draw parametric 3d curve with smoothing in R?
I have the data which are parametric 3d curve: 我有参数三维曲线的数据:
t x y z
0.000 3.734 2.518 -0.134
0.507 2.604 9.059 0.919
0.861 1.532 11.584 -0.248
1.314 1.015 1.886 -0.325
1.684 2.815 4.596 3.275
1.938 1.359 8.015 2.873
2.391 1.359 8.015 2.873
..............................
I found scatterplot3d and plot3d really cool. 我发现scatterplot3d和PLOT3D格式真的很酷。 But I need a smooth 3d curve. 但我需要一条平滑的三维曲线。
How can I plot it in R? 我如何在R中绘制它?
You can use spline
to interpolate between your points and smooth the curve. 您可以使用spline
在点之间进行插值并平滑曲线。
d <- read.delim(textConnection(
"t x y z
0.000 3.734 2.518 -0.134
0.507 2.604 9.059 0.919
0.861 1.532 11.584 -0.248
1.314 1.015 1.886 -0.325
1.684 2.815 4.596 3.275
1.938 1.359 8.015 2.873
2.391 1.359 8.015 2.873"
), sep=" ")
ts <- seq( from = min(d$t), max(d$t), length=100 )
d2 <- apply( d[,-1], 2, function(u) spline( d$t, u, xout = ts )$y )
library(scatterplot3d)
p <- scatterplot3d(d2, type="l", lwd=3)
p$points3d( d[,-1], type="h" )
As per @Spacedman's comment, you could also use rgl
: this allows you to interactively rotate the scene. 根据@Spacedman的评论,你也可以使用rgl
:这允许你以交互方式旋转场景。
library(rgl)
plot3d( d2, type="l", lwd=5, col="navy" )
points3d(d[,-1])
spheres3d(d[,-1], radius=.1, col="orange")
segments3d( matrix( t( cbind( d[,-1], d[,2:3], 0 ) ), nc=3, byrow=TRUE ) )
planes3d(0,0,1,0, col="yellow", alpha=.5) # Plane z=0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.