1 | angular_velocity(data, xDist, yDist)
|
data |
|
xDist |
|
yDist |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (data, xDist, yDist)
{
data$AngularVelocity <- rep(NA, nrow(data))
for (i in 2:nrow(data)) {
if (!is.na(data$GazePointX[i]) & !is.na(data$GazePointX[i -
1])) {
timeDiff <- (data$Timestamp[i] - data$Timestamp[i -
1]) * 10^(-6)
x <- (data$EyeLocX[i] + data$EyeLocX[i - 1])/2
y <- (data$EyeLocY[i] + data$EyeLocY[i - 1])/2
z <- (data$EyeLocZ[i] + data$EyeLocZ[i - 1])/2
a <- sqrt(z^2 + (x - xDist * data$GazePointXSmoothed[i])^2 +
(y - yDist * data$GazePointYSmoothed[i])^2)
b <- sqrt(z^2 + (x - xDist * data$GazePointXSmoothed[i -
1])^2 + (y - yDist * data$GazePointYSmoothed[i -
1])^2)
c <- sqrt((xDist * data$GazePointXSmoothed[i] - xDist *
data$GazePointXSmoothed[i - 1])^2 + (yDist *
data$GazePointYSmoothed[i] - yDist * data$GazePointYSmoothed[i -
1])^2)
angle <- 180/pi * acos((a^2 + b^2 - c^2)/(2 * a *
b))
data$AngularVelocity[i] <- angle/timeDiff
}
}
return(data)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.