eyetracking (version 1.1)

distance2point: Distance to Point

Description

Takes an x and y screen coordinate and returns the physical distance (in centimeters) from the observer to that point on the screen.

Usage

distance2point(x, y, viewerDistance, viewerHeight, resolutionX, resolutionY, screenWidth, screenHeight)

Arguments

x
The x coordinate of a point on a screen
y
The y coordinate of point on a screen
viewerDistance
Perpendicular distance from the viewer to the screen (cm)
viewerHeight
Vertical height of the viewer above screen center (cm)
resolutionX
The x resolution of the monitor (pixels)
resolutionY
The y resolution of the monitor (pixels)
screenWidth
The physical screen width (cm)
screenHeight
The physical screen height (cm)

Value

A distance in centimeters

Examples

Run this code
function( x, y, viewerDistance, viewerHeight, resolutionX, resolutionY, screenWidth, screenHeight ) {
    
    centerX <- screenWidth / 2
    centerY <- screenHeight / 2 - viewerHeight
    
    targetX <- x / resolutionX * screenWidth
    targetY <- y / resolutionY * screenHeight
    
    dX <- targetX - centerX
    dY <- targetY - centerY
    
    screenDistance <- sqrt( dX^2 + dY^2 )
    
    sqrt( ( viewerDistance^2 + screenDistance^2) )
    
  }

Run the code above in your browser using DataLab