如果我使用此公式的像素距离:
sqrt((x1-x2).^2+.(y1-y2)^2))
Run Code Online (Sandbox Code Playgroud)
我怎样才能把它转换成CM?
调用'ScreenPixelsPerInch'属性:
dpix=sqrt((x1-x2)^2+(y1-y2)^2); %# calculate distance in pixels
pixperinch=get(0,'ScreenPixelsPerInch'); %# find resolution of your display
dinch=dpix/pixperinch; %# convert to inches from pixels
dcm=dinch*2.54; %# convert to cm from inches
Run Code Online (Sandbox Code Playgroud)
或者对于单线方法:
dcm=sqrt((x1-x2)^2+(y1-y2)^2))/get(0,'ScreenPixelsPerInch')*2.54;
Run Code Online (Sandbox Code Playgroud)
编辑:您可能想检查您的系统是否获得屏幕大小和dpi正确.如果您知道显示器的尺寸和宽高比以及分辨率,则可以轻松完成.例如,我的设置:
宽屏16:9 23"显示器在1920x1080p
h^2+w^2=23^2 and h/w=9/16
Run Code Online (Sandbox Code Playgroud)
给
h=11.28 and w=20.05 inches
Run Code Online (Sandbox Code Playgroud)
get(0,'Screensize') 回报 [1 1 1920 1080]
并get(0,'ScreenPixelsPerInch')返回96
所以1920/20.05 = 95.76和1080/11.28 = 95.74
也许我很幸运,但这种方法对我有用.
| 归档时间: |
|
| 查看次数: |
11653 次 |
| 最近记录: |