r - 序列向量的转角:复平面
问题描述
我正在尝试计算复平面中顺序向量的转角。请参阅下面的代码以获取演示数据框和我计算角度的尝试。
角度的符号似乎是正确的:左转为正,右转为负。但是,当我参考该图时,转向角度看起来不正确。注意:我想要转角而不是矢量之间的角度。图片供参考:
set.seed(123)
# Generate a random path and plot it
path.short.random <- function(points = 6) {
x <- runif(points, -1, 1)
y <- rnorm(points, 0, 0.25)
i <- order(x, y)
x <- x[i]
y <- y[i]
path <- data.frame(x = x, y = y)
plot(x, y, main = "Random Path", asp = 1)
# draw arrows from point to point
s <- seq(length(x) - 1) # one shorter than data
arrows(x[s], y[s], x[s + 1], y[s + 1], col = 1:points)
path
}
# Save the path as a data frame
df <- path.short.random()
# Compute sequential turning angles
get.angles <- function(df) {
df$polar <- complex(real = df$x, imaginary = df$y)
df$displacement <- c(0, diff(df$polar))
diff(Arg(df$displacement[2:nrow(df)]))
}
get.angles(df)
解决方案
推荐阅读
- angular - 错误 TS1192:模块“http”没有默认导出
- batch-file - 如何使用 Windows Batch 读取和编辑 (>3GB) csv 文件?
- react-native - 创建IOS后无法打开新项目反应本机
- python - 如何使用 discord.py 获取语音频道的所有成员
- google-chrome - Google Chrome 控制台 - 多个命令?
- python-3.x - 如何在 Django 中重新连接到 RDS psql DB
- javascript - 检查被点击的 dom 元素是否改变了当前网页
- react-native - undefined 不是对象(评估 '_this2.getInfoFromToken')
- c# - 单击时突出显示图表区域
- c# - 使用辅助表列值添加下拉列表