virakri / eye-tracking-ios-prototype

MIT License
140 stars 35 forks source link

phoneScreenSize value #3

Open kavishjuneja11 opened 5 years ago

kavishjuneja11 commented 5 years ago

@virakri : How did you come up with : phoneScreenSize - width: 0.0623908297, height: 0.135096943231532 ?

virakri commented 5 years ago

Hi @kavishjuneja11, It’s the actual size of the screen of iPhone X (6.24 cm * 13.51cm)which I got them from using the screen actual pixel count divided by the screen resolution.

kavishjuneja11 commented 5 years ago

@virakri : according to https://support.apple.com/kb/SP770?locale=en_US the screen size of iPhone X is : 7.0866 cm * 14.351 cm.

a1209910 commented 5 years ago

Hi @virakri, I have a related question: What is the heightCompensation? I am trying to use the App on the new iPad Pro. Thanks

Schemetrical commented 5 years ago

@a1209910 I'm assuming heightCompensation relates to how the camera is a certain distance above the center of the screen. Not sure what the units are, maybe points?

ValentinoPalomba commented 4 years ago

Hi, can you explain how to make the division? I'm struggling for different phone

Atinder1989 commented 4 years ago

@virakri : can you explain how to calculate heightCompensation(312) and phoneScreenSize -( width: 0.0623908297, height: 0.135096943231532 ) for differenct iOS Device. I am struggling to calculate values for different iOS Devices.

rlalpha commented 3 years ago

You can calculate by the screen resolution and PPI (pixels per inch) since size include some non-monitor portion

(screen_width_pixel/ppi)/(screen_heigth_pixel/ppi) = width / height ## phoneScreenSize (1125/458)/(2436/458) = 0.0623908297/0.135096943231532 1125/458

a_ratio=(1125/458)/0.0623908297
b_ratio=(2436/458)/0.135096943231532

# e.g. iPhone X
x=1125/458
y=2436/458
print(x/a_ratio)
# 0.0623908297
print(y/b_ratio)
# 0.135096943231532 

# e.g. iPhone XS Max
x=1242/458
y=2688/458
print(x/a_ratio)
# 0.0688794759888
print(y/b_ratio)
# 0.1490724890830698

image image

Atinder1989 commented 3 years ago

You can calculate by the screen resolution and PPI (pixels per inch) since size include some non-monitor portion

(screen_width_pixel/ppi)/(screen_heigth_pixel/ppi) = width / height ## phoneScreenSize (1125/458)/(2436/458) = 0.0623908297/0.135096943231532 1125/458

a_ratio=(1125/458)/0.0623908297
b_ratio=(2436/458)/0.135096943231532

# e.g. iPhone X
x=1125/458
y=2436/458
print(x/a_ratio)
# 0.0623908297
print(y/b_ratio)
# 0.135096943231532 

# e.g. iPhone XS Max
x=1242/458
y=2688/458
print(x/a_ratio)
# 0.0688794759888
print(y/b_ratio)
# 0.1490724890830698

image image

What about height compensation( iphoneX=312) for different devices?

GustavoHoreste commented 8 months ago

Hi @virakri, I have a related question: What is the heightCompensation? I am trying to use the App on the new iPad Pro. Thanks

Hi your Did you manage to get it to work on the iPad?

GustavoHoreste commented 8 months ago

This code defines a computed property screenSize that returns the physical screen size of the device in points. It uses the screen's native width and height in points, the device's scale factor, and an assumed pixels per inch (PPI) value to calculate the physical width and height in inches. The width and height ratios are then computed based on the native resolution and scale factor, resulting in a CGSize object representing the calculated ratios.


// Computed property to get the physical screen size in points
static var screenSize: CGSize {
    // Get the native width and height of the screen in points
    let screenWidthPoints: CGFloat = UIScreen.main.nativeBounds.width
    let screenHeightPoints: CGFloat = UIScreen.main.nativeBounds.height
    // Substitute the real PPI (pixels per inch) of the device, assuming 458 PPI here
    let ppi: CGFloat = UIScreen.main.scale * 458 
    // Calculate the physical width and height of the screen in inches
    let physicalWidth: CGFloat = screenWidthPoints / ppi
    let physicalHeight: CGFloat = screenHeightPoints / ppi

    // Calculate the width and height ratios based on the screen's native resolution and scale factor
    let widthRatio = physicalWidth / (screenWidthPoints / UIScreen.main.scale)
    let heightRatio = physicalHeight / (screenHeightPoints / UIScreen.main.scale)

    // Return a CGSize representing the width and height ratios
    return CGSize(width: widthRatio, height: heightRatio)
}