trajectory analysis

Hello everyone,

I have the x, y coordinates (in meters) of an object. The frequency of capture is 30 frames per second. I need to calculate the speed and acceleration at each frame. any idea?

I'll appreaciate any help

  x                 y

|1|47.7241|26.2659|
|2|47.6629|26.0827|
|3|47.6016|25.8996|
|4|47.1948|25.6156|
|5|46.7879|25.3316|
|6|46.3811|25.0476|
|7|45.9742|24.7636|
|8|45.5674|24.4796|
|9|45.1605|24.1957|
|10|44.7537|23.9117|
|11|44.3468|23.6277|
|12|43.9399|23.3437|
|13|43.5331|23.0597|
|14|43.1262|22.7758|
|15|42.7194|22.4918|
|16|42.3125|22.2078|
|17|41.9057|21.9238|
|18|41.4988|21.6398|
|19|41.0920|21.3558|
|20|40.6851|21.0719|
|21|40.2783|20.7879|
|22|39.8714|20.5039|
|23|39.4646|20.2199|
|24|39.0577|19.9359|
|25|38.6509|19.6520|
|26|38.2440|19.3680|
|27|37.8372|19.0840|
|28|37.4303|18.8000|
|29|37.0234|18.5160|
|30|36.6166|18.2320|
|31|36.2097|17.9481|
|32|35.8029|17.6641|
|33|35.3960|17.3801|
|34|34.9892|17.0961|
|35|34.5823|16.8121|
|36|34.3687|16.6736|
|37|34.1550|16.5350|
|38|33.9414|16.3965|
|39|33.7277|16.2579|
|40|33.5141|16.1193|
41|33.3004|15.9808|
|42|33.0868|15.8422|
|43|32.8731|15.7037|
|44|32.6595|15.5651|
|45|32.4458|15.4265|
|46|32.2322|15.2880|
|47|32.0185|15.1494|
|48|31.8049|15.0109|
|49|31.5912|14.8723|
|50|31.3776|14.7338|
|51|31.1639|14.5952|
|52|30.9503|14.4566|
|53|30.7366|14.3181|
|54|30.5230|14.1795|
|55|30.3093|14.0410|
|56|30.0957|13.9024|
|57|29.8820|13.7638|
|58|29.6684|13.6253|
|59|29.4547|13.4867|
|60|29.2411|13.3482|
|61|29.0274|13.2096|
|62|28.8137|13.0710|
|63|28.6001|12.9325|
|64|28.3864|12.7939|
|65|28.1728|12.6554|
|66|27.9591|12.5168|
|67|27.7455|12.3783|
|68|27.5318|12.2397|
|69|27.3182|12.1011|
|70|27.1045|11.9626|
|71|26.8909|11.8240|
|72|26.6772|11.6855|
|73|26.4636|11.5469|
|74|26.2499|11.4083|
|75|26.0363|11.2698|
|76|25.8226|11.1312|
|77|25.6090|10.9927|
|78|25.3953|10.8541|
|79|25.1817|10.7155|
|80|24.9680|10.5770|
|81|24.7544|10.4384|
|82|24.5407|10.2999|
|83|24.3271|10.1613|
|84|24.1134|10.0228|
|85|23.8998|9.8842|
|86|23.6861|9.7456|
|87|23.4725|9.6071|
|88|23.2588|9.4685|
|89|23.0368|9.5760|
|90|22.8147|9.6835|
|91|22.5926|9.7910|
|92|22.3706|9.8984|
|93|22.1485|10.0059|
|94|21.9264|10.1134|
|95|21.7044|10.2209|
|96|21.4823|10.3284|
|97|21.2602|10.4358|
|98|21.0382|10.5433|
|99|20.8161|10.6508|
|100|20.5940|10.7583|
|101|20.3720|10.8657|
|102|20.1499|10.9732|
|103|19.9278|11.0807|
|104|19.7058|11.1882|
|105|19.4837|11.2957|
|106|19.2617|11.4031|
|107|19.0396|11.5106|
|108|18.8175|11.6181|
|109|18.5955|11.7256|
|110|18.3734|11.8331|
|111|18.1513|11.9405|
|112|17.9293|12.0480|
|113|17.7072|12.1555|
|114|17.4851|12.2630|
|115|17.2631|12.3705|
|116|17.0410|12.4779|
|117|16.8189|12.5854|
|118|16.5969|12.6929|
|119|16.3748|12.8004|
|120|16.1527|12.9079|
|121|15.9307|13.0153|
|122|15.7086|13.1228|
|123|15.4865|13.2303|
|124|15.2645|13.3378|
|125|15.0424|13.4452|
|126|14.8203|13.5527|
|127|14.5983|13.6602|
|128|14.3762|13.7677|
|129|14.1541|13.8752|
|130|13.9321|13.9826|
|131|13.7100|14.0901|
|132|13.4880|14.1976|
|133|13.2659|14.3051|
|134|13.0438|14.4126|
|135|12.8218|14.5200|
|136|12.5997|14.6275|
|137|12.3776|14.7350|
|138|12.1556|14.8425|
|139|11.9335|14.9500|
|140|11.7114|15.0574|
|141|11.4894|15.1649|
|142|11.2673|15.2724|
|143|11.0452|15.3799|
|144|10.8232|15.4874|
|145|10.6011|15.5948|
|146|10.3790|15.7023|
|147|10.1570|15.8098|
|148|9.9349|15.9173|
|149|9.7128|16.0247|
|150|9.4908|16.1322|
|151|9.2687|16.2397|
|152|9.0466|16.3472|
|153|8.6554|17.1089|
|154|8.2642|17.8707|
|155|7.8730|18.6324|
|156|7.4818|19.3942|
|157|7.0906|20.1559|
|158|6.6994|20.9177|
|159|6.3082|21.6794|
|160|5.9170|22.4412|

If I understand you correctly, this would give you instant velocity on each "frame" (I'm not sure what you mean with this), following the same logic you can calculate the variation of speed over time (acceleration).

library(dplyr)

sample_df <- data.frame(
    x = c(47.7241,47.6629,47.6016,47.1948,46.7879,
          46.3811,45.9742,45.5674,45.1605,44.7537,44.3468,43.9399,
          43.5331,43.1262,42.7194,42.3125,41.9057,41.4988,41.092,
          40.6851,40.2783,39.8714,39.4646,39.0577,38.6509,38.244,
          37.8372,37.4303,37.0234,36.6166,36.2097,35.8029,35.396,
          34.9892,34.5823,34.3687,34.155,33.9414,33.7277,33.5141,
          33.3004,33.0868,32.8731,32.6595,32.4458,32.2322,32.0185,
          31.8049,31.5912,31.3776,31.1639,30.9503,30.7366,30.523,
          30.3093,30.0957,29.882,29.6684,29.4547,29.2411,29.0274,
          28.8137,28.6001,28.3864,28.1728,27.9591,27.7455,27.5318,
          27.3182,27.1045,26.8909,26.6772,26.4636,26.2499,26.0363,
          25.8226,25.609,25.3953,25.1817,24.968,24.7544,24.5407,
          24.3271,24.1134,23.8998,23.6861,23.4725,23.2588,23.0368,
          22.8147,22.5926,22.3706,22.1485,21.9264,21.7044,21.4823,
          21.2602,21.0382,20.8161,20.594,20.372,20.1499,19.9278,19.7058,
          19.4837,19.2617,19.0396,18.8175,18.5955,18.3734,18.1513,
          17.9293,17.7072,17.4851,17.2631,17.041,16.8189,16.5969,
          16.3748,16.1527,15.9307,15.7086,15.4865,15.2645,15.0424,
          14.8203,14.5983,14.3762,14.1541,13.9321,13.71,13.488,
          13.2659,13.0438,12.8218,12.5997,12.3776,12.1556,11.9335,
          11.7114,11.4894,11.2673,11.0452,10.8232,10.6011,10.379,
          10.157,9.9349,9.7128,9.4908,9.2687,9.0466,8.6554,8.2642,
          7.873,7.4818,7.0906,6.6994,6.3082,5.917),
    y = c(26.2659,26.0827,25.8996,25.6156,25.3316,
          25.0476,24.7636,24.4796,24.1957,23.9117,23.6277,23.3437,
          23.0597,22.7758,22.4918,22.2078,21.9238,21.6398,21.3558,
          21.0719,20.7879,20.5039,20.2199,19.9359,19.652,19.368,
          19.084,18.8,18.516,18.232,17.9481,17.6641,17.3801,
          17.0961,16.8121,16.6736,16.535,16.3965,16.2579,16.1193,15.9808,
          15.8422,15.7037,15.5651,15.4265,15.288,15.1494,15.0109,
          14.8723,14.7338,14.5952,14.4566,14.3181,14.1795,14.041,
          13.9024,13.7638,13.6253,13.4867,13.3482,13.2096,13.071,
          12.9325,12.7939,12.6554,12.5168,12.3783,12.2397,12.1011,
          11.9626,11.824,11.6855,11.5469,11.4083,11.2698,11.1312,
          10.9927,10.8541,10.7155,10.577,10.4384,10.2999,10.1613,
          10.0228,9.8842,9.7456,9.6071,9.4685,9.576,9.6835,9.791,
          9.8984,10.0059,10.1134,10.2209,10.3284,10.4358,10.5433,
          10.6508,10.7583,10.8657,10.9732,11.0807,11.1882,11.2957,
          11.4031,11.5106,11.6181,11.7256,11.8331,11.9405,12.048,
          12.1555,12.263,12.3705,12.4779,12.5854,12.6929,12.8004,
          12.9079,13.0153,13.1228,13.2303,13.3378,13.4452,13.5527,
          13.6602,13.7677,13.8752,13.9826,14.0901,14.1976,14.3051,
          14.4126,14.52,14.6275,14.735,14.8425,14.95,15.0574,15.1649,
          15.2724,15.3799,15.4874,15.5948,15.7023,15.8098,15.9173,
          16.0247,16.1322,16.2397,16.3472,17.1089,17.8707,18.6324,
          19.3942,20.1559,20.9177,21.6794,22.4412)
)

sample_df %>% 
    mutate(vel = sqrt((lag(x) - x) ^ 2 + (lag(y) - y) ^ 2) / (1/30)) %>% 
    as_tibble() # Just for friendly printing
#> # A tibble: 160 x 3
#>        x     y   vel
#>    <dbl> <dbl> <dbl>
#>  1  47.7  26.3 NA   
#>  2  47.7  26.1  5.79
#>  3  47.6  25.9  5.79
#>  4  47.2  25.6 14.9 
#>  5  46.8  25.3 14.9 
#>  6  46.4  25.0 14.9 
#>  7  46.0  24.8 14.9 
#>  8  45.6  24.5 14.9 
#>  9  45.2  24.2 14.9 
#> 10  44.8  23.9 14.9 
#> # … with 150 more rows

Created on 2020-03-26 by the reprex package (v0.3.0.9001)

For future posts, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

thank you, @andresrcs

that's what I needed. I didn't know the lag function.
I guess the acceleration formula is this, isn't it?

mutate(acc = sqrt((lag(vel) - vel) ^ 2) / (1/30))

I'm afraid not, this seems like a homework question so I'll let you figure it out, as a hint, that formula was for calculating distance between two points on a plane.

Thank you. I`ll use you information to do it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.