【C++】三角関数
画角からの焦点距離
#define _USE_MATH_DEFINES #include <iostream> #include <cmath> using namespace std; int main() { auto toRadian = [](float deg){ return deg * static_cast<float>(M_PI) / 180.f; }; auto width = 800.f; auto height = 600.f; auto aspect = width / height; auto fov = toRadian(45.f); auto distance = width / aspect / 2.f / tan(fov / 2.f); cout << "幅:" << width << endl; cout << "高さ:" << height << endl; cout << "アスペクト比:" << aspect << endl; cout << "画角:" << fov << endl; cout << "焦点距離:" << distance << endl; return 0; }