fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. float screen_to_angle(const float pixel_dist, const float screen_width, const float fov)
  5. {
  6. return atanf(pixel_dist / -((screen_width / 2.F) / tanf(fov / 2.F)));
  7. }
  8.  
  9. float ratio_at_dist(const float dist, const float fov1, const float fov2)
  10. {
  11. const auto ang1 = screen_to_angle(dist, 1920, fov1 * 3.1415926 / 180.F);
  12. const auto ang2 = screen_to_angle(dist, 1920, fov2 * 3.1415926 / 180.F);
  13.  
  14. return ang1 / ang2;
  15. }
  16.  
  17. int main()
  18. {
  19. std::cout << "Ratio at 5px from center: ";
  20. std::cout << ratio_at_dist(5.F, 51.F, 103.F) << std::endl;
  21.  
  22. std::cout << "Ratio at 960px from center: ";
  23. std::cout << ratio_at_dist(960.F, 51.F, 103.F) << std::endl;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Ratio at 5px from center: 0.379408
Ratio at 960px from center: 0.495146