R中运动路径的矢量加(减)运算

R中运动路径的矢量加(减)运算,r,vector,adehabitathr,R,Vector,Adehabitathr,我有一个数据框,其中包括动物在lat/lon坐标中的运动路径 由此我得到了地面上的速度和方向。数据帧还包含相对于动物位置的风矢量,即时间t时相对于动物的风速和风向 我想使用矢量加法来计算动物在空气中的运动,而不是相对于地面的运动,以便计算动物必须遵循的运动矢量,以便在风条件下生成其地理参考轨迹 以下是一些示例数据: lat lon speed.geo dir.geo speed.flow dir.flow 1 58.65417 -3.179046

我有一个数据框,其中包括动物在lat/lon坐标中的运动路径

由此我得到了地面上的速度和方向。数据帧还包含相对于动物位置的风矢量,即时间t时相对于动物的风速和风向

我想使用矢量加法来计算动物在空气中的运动,而不是相对于地面的运动,以便计算动物必须遵循的运动矢量,以便在风条件下生成其地理参考轨迹

以下是一些示例数据:

        lat       lon  speed.geo   dir.geo speed.flow   dir.flow
1  58.65417 -3.179046        NaN   0.00000  0.4308415 151.865239
2  58.65483 -3.180403 0.44041631 313.16209  0.4308415 151.865239
3  58.66102 -3.187734 0.05788974 328.34835  0.1310305  95.664332
4  58.66409 -3.190197 0.15473413 337.35945  0.2018593 150.394597
5  58.67433 -3.182058 0.04170939  22.44943  0.1635966  21.383810
6  58.67475 -3.181318 0.24299875  42.15219  0.1635966  21.383810
7  58.67520 -3.181994 0.21488370 322.13387  0.1635966  21.383810
8  58.67472 -3.181549 0.20505462 154.49798  0.1635966  21.383810
9  58.67325 -3.178166 1.11257613 129.96324  0.1379763   4.478803
10 58.67234 -3.177124 0.45663637 149.03759  0.1357501 357.369873
这是一个dput:

structure(list(lat = c(6501.55844075436, 6501.63236163928, 6502.32219361407, 
6502.66453486307, 6503.80350448795, 6503.85070971918, 6503.90114368413, 
6503.84707158286, 6503.68242346453, 6503.5817192008), lon = c(489.610443265389, 
489.531898544151, 489.108436319722, 488.966512812528, 489.441757188732, 
489.484800489562, 489.445733748482, 489.471394150017, 489.667148867539, 
489.727314726641), speed.geo = c(NaN, 0.440416314391926, 0.0578897406018802, 
0.154734132490158, 0.0417093915733849, 0.242998750785266, 0.214883703663591, 
0.205054624380294, 1.11257613127184, 0.45663636779519), dir.geo = c(0, 
313.1620935132, 328.348350423236, 337.359451215582, 22.4494313495932, 
42.1521946548759, 322.133869730753, 154.497980751214, 129.963235575701, 
149.037589410303), speed.flow = c(0.430841479520486, 0.430841479520486, 
0.131030528451571, 0.201859265857843, 0.16359657788002, 0.16359657788002, 
0.16359657788002, 0.16359657788002, 0.137976282783002, 0.135750095569998
), dir.flow = c(151.865238547752, 151.865238547752, 95.6643315716291, 
150.394596637891, 21.3838095217828, 21.3838095217828, 21.3838095217828, 
21.3838095217828, 4.47880272242145, 357.369872864835)), .Names = c("lat", 
"lon", "speed.geo", "dir.geo", "speed.flow", "dir.flow"), row.names = c(NA, 
-10L), class = "data.frame")

预期输出应为数据框中的另外两列,表示动物相对于气流的运动矢量,即其飞行速度和方向。它实际上是基本的三角测量法,但我不能用R来计算它。

要求向量和,你们需要在笛卡尔坐标系上,而不是极坐标系上。所以,你应该把它转换成x-y分量系统,然后求和

另一种方法是用复数来表示速度和方向,比如x是实的,y是虚的。 以下代码将速度值转换为复数,求和,并提取模数速度和参数dir。方向将再次转换为度

library(dplyr)
df<-mutate(df,
       complex.geo = complex(modulus = speed.geo, 
                             argument = dir.geo/360*2*pi),
       complex.flow = complex(modulus = speed.flow,
                              argument = (dir.flow/360*2*pi)),
       complex.relat = complex.geo-complex.flow,
       speed.relat = Mod(complex.relat),
       dir.relat = ifelse(Arg(complex.relat)*360/(2*pi)<0,
                          Arg(complex.relat)*360/(2*pi)+360,
                          Arg(complex.relat)*360/(2*pi))) %>%
select(lat,lon,speed.geo,dir.geo,speed.flow,dir.flow,speed.relat,dir.relat)

你能显示预期输出吗?我已经修改了问题@akrun