Search code examples
rgeometryeye-tracking

X and Y coordinates in R. Is there an obvious way to remove data that is a certain radius away from a given point?


I am trying to clean up some eye tracking data in which people are told to focus on the middle of the screen. However, the data is somewhat noisy and I am trying to clean it up in a proper way.

I have created some code that emulates the kind of data that I have and the methods I am trying to use as well as what I am presenting below.

The data complete with noise looks as follows: enter image description here

I have tried to use a simple formula to throw all samples further than some pixels from the centre away such as:

results[results$x <= xmid+threshold & results$x >= xmid-threshold,]

But that results in data in a square shape rather than a circle: enter image description here

I have tried to think about what to do here and have made it as far as to define a circle that encompasses the area that I am interested in:

enter image description here

However, I can not see a straightforward way to only pick data within that area.The solutions I have tried have required several for loops and still not given me the result I was hoping for.

I hope that some of you can point me in the right direction here. Maybe the problem is even trivial to solve in some manner that I have not yet considered? Thanks for reading this far and here is the code if you think that you can help :)


Solution

  • To check whether point lies in circular region with radius threshold around center xmid, ymid, you can use expression (^ denotes 2-nd power, squaring)

     (x-xmid)^2 + (y-ymid)^2 <= threshold^2