Skip to content

Instantly share code, notes, and snippets.

@rainyear
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rainyear/d248788b841b9910d6d7 to your computer and use it in GitHub Desktop.
Save rainyear/d248788b841b9910d6d7 to your computer and use it in GitHub Desktop.
Visual Angle.
// cal Pix size with given visual angle and screen info.
var scr = {
xpixels: 1024,
ypixels: 768,
width: 360, //mm
height: 270, //mm
}
var ang2pix = function(screen, angle, distense){
var targetWidth = angle.h * distense / (180 / 3.14);
var targetHeight = angle.v * distense / (180 / 3.14);
return {
xpixels: targetWidth * screen.xpixels / screen.width,
ypixels: targetHeight * screen.ypixels / screen.height
}
}
// @screen
var scr = {
xpixels: 1024,
ypixels: 768,
width: 360, //mm
height: 270, //mm
}
// @target
/*
{
xpixels: 250,
ypixels: 250
}
*/
// @distense
// 120 cm = 1200 mm
var calVisualAngle = function(screen, target, distense){
var targetWidth = screen.width * target.xpixels / screen.xpixels;
var targetHeight = screen.height * target.ypixels / screen.ypixels;
return {
h: targetWidth / distense * 180 / 3.14,
v: targetHeight / distense * 180 / 3.14
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment