问题
In THREE.js we construct a camera using the following function
const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
We know from optics that the field of view of a camera is related to the focal length by the following equation
FOV = arctan(d/2f)
where FOV
is the vertical FOV in degrees, d
is the height of the image plane in mm, and f
is the focal length of the camera in mm.
After reading the documentation on the matter, it seems as though d
is set by default to be 35mm / aspectRatio
.
We can express FOV
like this
FOV = arctan((35/(width/height))/2f) = arctan(filmHeight / 2f)
As a sanity check, I printed the following value, to see if I would get back the input FOV of 75
.
Math.atan(camera.getFilmHeight()/(2 * camera.getFocalLength())) * 180 / Math.PI;
But.. this value comes out to be 37.50000000000001
which is exactly half of the expected focal length of 75
.
So, I was wondering if I did the math wrong somewhere, or if I'm misinterpreting THREE.js's reported values.
回答1:
The .fov angle is the
Camera frustum vertical field of view, from bottom to top of view, in degrees.
But what you calculate is, the angle of the center of the view to the top:
Math.atan( (camera.getFilmHeight()/2) / camera.getFocalLength())) * 180 / Math.PI;
this is indeed the half of .fov:
fov = 2 * Math.atan( (camera.getFilmHeight()/2) / camera.getFocalLength())) * 180 / Math.PI;
来源:https://stackoverflow.com/questions/53881693/three-js-perspectivecamera-focallength-off-by-a-factor-of-two-inconsistent-with