首页 > 解决方案 > 序列向量的转角:复平面

问题描述

我正在尝试计算复平面中顺序向量的转角。请参阅下面的代码以获取演示数据框和我计算角度的尝试。

角度的符号似乎是正确的:左转为正,右转为负。但是,当我参考该图时,转向角度看起来不正确。注意:我想要转角而不是矢量之间的角度。图片供参考:

在此处输入图像描述

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)

标签: rvectoranglecomplex-numbers

解决方案


推荐阅读