【发布时间】:2021-12-24 08:46:00
【问题描述】:
我正在寻找一种方法来偏移通过 xy 坐标在一个方向(在 R 中)定义的任意曲线。我可以使用 {polyclip} 包在两个方向上偏移曲线。
library(polyclip)
#> polyclip 1.10-0 built from Clipper C++ version 6.4.0
# Make a curve
t <- seq(10, 0, by = -0.05)
curve <- data.frame(
x = t * cos(t), y = t * sin(t)
)
plot(curve, type = 'l')
# Find offset
offset <- polylineoffset(curve, delta = 0.5,
jointype = "round", endtype = "openbutt")[[1]]
offset <- as.data.frame(offset) # xy coordinates
lines(offset, col = "red")
因为曲线上的点比偏移量的delta 参数间隔更近,所以我可以通过找出一个点与下一个点之间的距离最大的位置来启发式地拆分偏移量。
distance <- c(0, sqrt(diff(offset$x)^2 + sqrt(diff(offset$y)^2)))
max_dist <- which.max(distance)
plot(curve, type = 'l')
lines(offset[1:(max_dist - 1), ], col = 3)
lines(offset[max_dist:nrow(offset), ], col = 4)
由reprex package (v2.0.1) 于 2021 年 11 月 11 日创建
但是,我希望能够拆分偏移量,或者仅在一个方向上偏移,即使曲线上的点之间的距离比偏移距离更远。有没有办法在 R 中做到这一点?我没有与 {polyclip} 包结婚,使用另一个包的解决方案也可以。
【问题讨论】: