I have a data frame that looks like this:
structure(list(K = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), T = c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L,
26L, 27L, 28L, 29L, 30L, 31L, 32L), X = c(26.892, 23.904, 23.904,
23.904, 23.904, 23.904, 23.904, 23.904, 23.904, 20.916, 20.916,
20.916, 20.916, 20.916, 20.916, 20.916, 20.916, 20.916, 20.916,
20.916, 29.88, 20.916, 14.94, 8.964, 8.964, 5.976, 5.976, 5.976,
5.976, 5.976, 5.976, 5.976, 5.976, 5.976, 857.56, 860.54, 857.56,
857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56,
857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56,
857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56, 857.56,
857.56, 857.56, 857.56, 857.56, 857.56), Y = c(167.33, 167.33,
164.34, 164.34, 164.34, 164.34, 164.34, 164.34, 164.34, 143.42,
143.42, 143.42, 143.42, 143.42, 143.42, 143.42, 143.42, 143.42,
143.42, 143.42, 176.29, 182.27, 185.26, 188.24, 188.24, 188.24,
188.24, 188.24, 188.24, 188.24, 188.24, 188.24, 188.24, 188.24,
256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97,
256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97,
256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97,
256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97, 256.97
), V = c(2.1128, 1.494, 0, 0, 0, 0, 0, 10.564, 10.564, 0, 0,
0, 0, 0, 0, 0, 0, 0, 17.034, 19.422, 8.7114, 6.6814, 3.3407,
1.494, 1.494, 0, 0, 0, 0, 0, 0, 0, 0, 20.1, 0, 1.494, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1.494, 1.494), P = c(-135, -90, 0, 0, 0, 0, 0, -98.13,
-98.13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 74.745, 90, 149.04, 153.43,
153.43, 180, 180, 0, 0, 0, 0, 0, 0, 0, 0, 41.987, 0, 180, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 90, 90)), .Names = c("K", "T", "X", "Y", "V",
"P"), row.names = c(NA, 66L), class = "data.frame")
Since I have X, Y positions, to make two vectors, I should consider three X,Y positions to be able to compute for an angle. I know that:
theta <- acos( sum(a*b) / ( sqrt(sum(a * a)) * sqrt(sum(b * b)) ) )
from another stackoverflow answer (Angle between two vectors in R).
I need also to compute the angle per T as a factor within each K. I know I could use split
in this.
But how do I define the vector for the computation of the angle and the function for the angle itself? Thanks.
On this diagram, I have X,Y positions of a movement and I need to compute the angle of the movement. I hope that helps. It should also be noted that there is no angle possible for the first and last X,Y positions. Thanks