计算球体的相机fov距离 [英] calculate camera fov distance for sphere

查看:203
本文介绍了计算球体的相机fov距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算相机在球体上放大的最大距离,同时仍然在屏幕上显示所有球体。

I trying to calculate the max distance the camera can zoom in on a sphere while still displaying all of the sphere on screen.

var dist =  diameter / (2 * Math.tan( camera.fov * (Math.PI/180) / 2 ));

这放大了很多。球体的顶部和底部被剪裁。
我做错了什么?

this zooms in to much. The top and bottom of the sphere are clipped. What am i doing wrong?

小提琴

推荐答案

球体被裁剪的原因相同,如果你站在一个大球体附近,你可以'看到它的北极。

The sphere is being clipped for the same reason that if you stand close to a large sphere you can't see its "north pole".

你需要对通过球体前面的平面进行计算,而不是中心。

You need to do the calculation for a plane that passes through the front of the sphere, not its center.

因此,您计算的数量是到球体前面的最小距离。到中心的最小距离是你计算的数量加上球体的半径。

As a result, the quantity you calculated is the minimum distance to the front of the sphere. The minimum distance to its center is the quantity you calculated plus the sphere's radius.

(注意:由于球体的曲率,这将产生保守的近似值。)

(Note: this will yield a conservative approximation, due to the curvature of the sphere.)

编辑:好的,这是确切答案。

OK, here is the exact answer.

var dist =  radius / ( Math.sin( camera.fov * ( Math.PI / 180 ) / 2 ) );

小提琴: http://jsfiddle.net/x98Fk/3/

three.js相机视野是垂直视野,所以这是垂直方向的结果。如果窗口比它宽,那么你必须处理这个问题。

The three.js camera field-of-view is the vertical FOV, so this this the result for the vertical direction. If the window is narrower than it is wide, then you have to deal with that issue.

这篇关于计算球体的相机fov距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆