在R中,我想插入一个内插点之间距离恒定的任意路径 .
测试数据看起来像这样:
require("rgdal", quietly = TRUE)
require("ggplot2", quietly = TRUE)
r
coords
names(coords)
print(coords)
x y
-0.44409 0.551159
-1.06217 0.563326
-1.09867 0.310255
-1.09623 -0.273754
-0.67283 -0.392990
-0.03772 -0.273754
0.63633 -0.015817
0.86506 0.473291
1.31037 0.998899
1.43934 0.933198
1.46854 0.461124
1.39311 0.006083
1.40284 -0.278621
1.54397 -0.271321
p.orig
geom_point(colour = "yellow")
print(p.orig)
我尝试了不同的方法,但没有一个真正令人满意:
aspline (akima-package)
approx
bezierCurve
与 tourr -package我无法入手
aspline
来自akima-package的 aspline 在处理任意路径时会做一些奇怪的事情:
plotInt
data = coords) + geom_point(aes(x = x, y = y), data = coords))
N
require("akima", quietly = TRUE)
xy.int.ak
plotInt(xy.int.ak)
约
xy.int.ax
y = approx(y, n = N)$y)))
plotInt(xy.int.ax)
乍一看, approx 看起来很漂亮;然而,用真实数据测试它会让我对插值点之间的距离产生问题 . 平滑的三次插值也是一件好事 .
bezier
另一种方法是使用 bezier-curves ;我使用了以下implementation
source("bez.R")
xy.int.bz
plotInt(xy.int.bz)