Advertisement
simondp

Untitled

Feb 26th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.39 KB | None | 0 0
  1. # Emulate Eye tracking data and remove all that is x pixels away from the centre
  2. set.seed(007)
  3.  
  4. # Assume screen of 1920 by 1080 pixels
  5. xmax <- 1920
  6. ymax <- 1080
  7. ymid <- ymax/2
  8. xmid <- xmax/2
  9.  
  10. # Simulate some data that truly fixes on the centre screen
  11. sims <- 10000 # How many simulations
  12. xT <- rnorm(sims,xmid,20)
  13. yT <- rnorm(sims,ymid,20)
  14.  
  15. # Add noise where people fixed at random points of screen
  16. xN <- runif(sims/5,0,xmax)
  17. yN <- runif(sims/5,0,ymax)
  18.  
  19. # Merge together
  20. x <- c(xT,xN)
  21. y <- c(yT,yN)
  22. results <- data.frame(x,y)
  23.  
  24. # Plot all simulations
  25. plot(results, xlim=c(0,xmax), ylim=c(0,ymax))
  26.  
  27. # Try to subset part of data that is within radius of centre
  28. threshold <- 40 # Threshold set aggressive to clarify issue
  29. resultsSub <- results[results$x <= xmid+threshold & results$x >= xmid-threshold & results$y <= ymid+threshold & results$y >= ymid-threshold,]
  30.  
  31. # Plot obviously wrong solulution. Now a square is left rather than a circle
  32. plot(resultsSub, xlim=c(0,xmax), ylim=c(0,ymax))
  33.  
  34. # Potential way forward?
  35. # Centre as 0.0
  36. resultsC <- results
  37. resultsC$x <-  resultsC$x-xmid
  38. resultsC$y <-  resultsC$y-ymid
  39.  
  40. # Create circle with radius of threshold
  41. objects <- 100
  42. th = seq(0,(2*pi),2*pi/objects)
  43. thred =  th[seq(1,100,1)]
  44.  
  45. ### Default
  46. xposd = cos(thred)*40
  47. yposd = sin(thred)*40
  48.  
  49. # Somehow compare defined circle against data
  50. plot(resultsC)
  51. points(xposd,yposd, col="red")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement