horizontal resolution of the screen in pixels (e.g. 1920): 1366
vertical resolution of the screen in pixels (e.g. 1080): 768
diagonal of the screen in inches (e.g 24): 12.5
------
pixels per inch (PPI) = 125.37
------
pixels per square inch (PPI2) = 15716
------
dot pitch (DP) = 0.203
------
aspect ratio: 16:9 (wide TV)
------
screen dimensions:
------
width x height, diagonal [inches]:
------
10.9 x 6.13 , 12.5 @ 1366 * 768
------
width x height, diagonal [centimeters]:
------
27.68 x 15.56 , 31.75 @ 1366 * 768
------
this screen has 1.05 million pixels
#INPUTS
hres = raw_input('horizontal resolution of the screen in pixels (e.g. 1920): ')
vres = raw_input('vertical resolution of the screen in pixels (e.g. 1080): ')
diag_in = raw_input('diagonal of the screen in inches (e.g 24): ')
#inch to centimeter conversion factor
cmin = 2.54
#math for square root operation
import math
#define variables as float in order for pow() or ** respectively, to work
diag_in = float(diag_in) #diagonal in inches
hres = float(hres) #horizontal resolution
vres = float(vres) #vertical resolution
#formula derived from the diagonal and the ratio of the sides (resolution) using pythagoras
#height of the screen in inches
v_in = math.sqrt((diag_in**2)/(1+(hres**2/vres**2)))
"""alternative
a = pow(diag_in, 2)
b = (1+(pow(hres, 2)/pow(vres, 2)))
c = a/b
v_in = math.sqrt(c)
"""
#width of the screen in inches
h_in = float((v_in*hres))/(vres)
#convert to centimeters
h_cm = h_in*cmin
v_cm = v_in*cmin
diag_cm = diag_in*cmin
PPI = hres/h_in #pixels per inch <==> vres/v_in
PPI2 = (hres*vres)/(h_in*v_in) #pixels per square inch
DP = (h_cm*10)/hres #dot pitch (see: http://de.wikipedia.org/wiki/Pixelpitch)
pixels = round((hres*vres)/1000000., 2)
ratio = hres/vres
cine = 16./9
wide = 16./10
norm = 4./3
comp = 5./4
#so formats that don't match the exact standard aspect ratios
#this function checks if it's close enough, e.g. 1366*768 = 16:9
def is_btw(x,y,z):
if z > y >x:
return True
else:
return False
if is_btw((16./9.1),ratio,(16./8.9)):
ratio=cine
if is_btw((16./10.1),ratio,(16./9.9)):
ratio=wide
if is_btw((4./3.1),ratio,(4./2.9)):
ratio=norm
if is_btw((5./4.1),ratio,(5./3.9)):
ratio=comp
#-----end-function---------------------
def new_line():
print '------'
#OUTPUTS
new_line()
print 'pixels per inch (PPI) = ', round(PPI, 2)
new_line()
print 'pixels per square inch (PPI2) = ', int(PPI2)
new_line()
print 'dot pitch (DP) = ', round(DP, 3)
new_line()
#------------aspect_ratio------------------------------------------
if ratio == cine:
print 'aspect ratio: 16:9 (wide TV)'
elif ratio == wide:
print 'aspect ratio: 16:10 (wide PC)'
elif ratio == norm:
print 'aspect ratio: 4:3 (standard PC)'
elif ratio == comp:
print 'aspect ratio: 5:4 (PC)'
else: print 'this aspect ratio is not a standard format: ', int(hres), ':', int(vres)
new_line()
#-------------------------------------------------------------------
print 'screen dimensions:'
new_line()
print 'width x height, diagonal [inches]:'
new_line()
print round(h_in, 2), ' x ', round(v_in, 2), ', ',diag_in, ' @',int(hres),'*',int(vres)
new_line()
print 'width x height, diagonal [centimeters]:'
new_line()
print round(h_cm, 2), ' x ', round(v_cm, 2), ', ',diag_cm, ' @',int(hres),'*',int(vres)
new_line()
print 'this screen has', pixels, 'million pixels'
new_line()