代码之家  ›  专栏  ›  技术社区  ›  Carpetfizz

THREE.js透视相机焦距为2倍,与视野不一致

  •  1
  • Carpetfizz  · 技术社区  · 7 年前

    const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
    

    我们从光学上知道,摄像机的视场与焦距的关系如下式所示

    FOV = arctan(d/2f)
    

    哪里 FOV 是垂直视场,单位为度, d 是图像平面的高度,单位为mm,并且 f 是相机的焦距,单位为mm。

    读后 the documentation D 默认情况下设置为 35mm / aspectRatio .

    我们可以表达 视野

    FOV = arctan((35/(width/height))/2f) = arctan(filmHeight / 2f)
    

    作为一个健全性检查,我打印了以下值,以查看是否可以返回 75 .

    Math.atan(camera.getFilmHeight()/(2 * camera.getFocalLength())) * 180 / Math.PI;
    

    但是这个值被证明是 37.50000000000001

    正好是预期焦距的一半 .

    1 回复  |  直到 6 年前
        1
  •  6
  •   Rabbid76    7 年前

    这个 .fov 角度是最重要的

    但你要计算的是,视图中心到顶部的角度:

    Math.atan( (camera.getFilmHeight()/2) / camera.getFocalLength())) * 180 / Math.PI;
    

    这确实是我们的一半 .fov :

    fov = 2 * Math.atan( (camera.getFilmHeight()/2) / camera.getFocalLength())) * 180 / Math.PI;