PixelsPerDegree.m 1021 B

123456789101112131415161718192021222324252627282930
  1. % function PixelsPerDegree:
  2. %
  3. % This function returns the approximation of pixels per degree for each
  4. % dimension. It doesn't take into account the change in distance as we move to
  5. % the edges of the monitor.
  6. %
  7. % input:
  8. % width - width of monitor in meters
  9. % height - height of monitor in meters
  10. % distance - distance of the viewer in meters
  11. % widthPixels - width of moitor in pixels
  12. % heightPixels - height of monitor in pixels
  13. % output:
  14. % pxPerDeg - pixels per degree on X axis(approx.)
  15. % pyPerDeg - pixels per degree on Y axis(approx.)
  16. function [pxPerDeg, pyPerDeg] = PixelsPerDegree(width, height, distance, widthPixels, heightPixels)
  17. thetaWtotal = 2*atan2(width/2,distance)*180/pi;
  18. if (thetaWtotal < 0)
  19. thetaWtotal = 360 + thetaWtotal;
  20. end
  21. thetaHtotal = 2*atan2(height/2,distance)*180/pi;
  22. if (thetaHtotal < 0)
  23. thetaHtotal = 360 + thetaHtotal;
  24. end
  25. pxPerDeg = widthPixels/thetaWtotal;
  26. pyPerDeg = heightPixels/thetaHtotal;
  27. end