投影球体的半径 [英] Radius of projected Sphere

查看:135
本文介绍了投影球体的半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完善上一个问题



我如何将一个球体投射到屏幕上?

(2)给出了一个简单的解决方案:

 
在屏幕上的近似半径 [CLIP SPACE] =世界半径* cot(fov / 2)/ Z

with:
fov =视场角
Z = z从相机到球体的距离

结果在剪辑空间中,与视口大小相乘以获得像素大小

现在我的问题是我没有FOV。只有视图矩阵和投影矩阵是已知的。 (和视口的大小,如果有帮助的话)



任何人都知道如何从投影矩阵中提取视场?

< h2>更新:

这个近似值在我的情况下效果更好:

  float radius = glm :: atan(radius / distance); 
radius * = glm :: max(viewPort.width,viewPort.height)/ glm :: radians(fov);


解决方案

更新: >



由于您有视图和投影矩阵,下面是一种方法,但它可能不是最短的:


  • 使用视图矩阵将球体的中心转换为视图空间:调用结果点C

  • 转换球体表面上的点,例如在世界坐标系中的C +(r,0,0),其中r是球体的世界半径,进入视空间;调用结果点S

  • 计算rv =从C到S(在视图空间中)的距离

  • 让视图坐标中的S1点为C +( rv,0,0) - 即视图空间中球体表面上的另一个点,线C - > S1垂直于外观矢量

  • 项目C和S1使用投影矩阵作为Cs和S1s到屏幕坐标计算屏幕半径= Cs和S1之间的距离


但是,就像Brandorf说的那样,如果你可以保存像FOVy这样的摄像机变量,它会容易得多。 : - )

更新:
以上是一个更有效的变体:使投影矩阵反转。使用它将视口边缘转换回视图空间。然后,您不必将每个盒子投影到屏幕坐标中。



更好的是,对视图矩阵进行相同处理,并将相机平截头体转换回世界空间。比较许多盒子会更有效率;但很难弄清楚数学。


i want to refine a previous question:

How do i project a sphere onto the screen?

(2) gives a simple solution:

approximate radius on screen[CLIP SPACE] = world radius * cot(fov / 2) / Z

with:
fov = field of view angle
Z   = z distance from camera to sphere

result is in clipspace, multiply by viewport size to get size in pixels

Now my problem is that i don't have the FOV. Only the view and projection matrices are known. (And the viewport size if that does help)

Anyone knows how to extract the FOV from the projection matrix?

Update:

This approximation works better in my case:

float radius = glm::atan(radius/distance);
radius *= glm::max(viewPort.width, viewPort.height) / glm::radians(fov);

解决方案

Update: see below.

Since you have the view and projection matrices, here's one way to do it, though it's probably not the shortest:

  • transform the sphere's center into view space using the view matrix: call the result point C
  • transform a point on the surface of the sphere, e.g. C+(r, 0, 0) in world coordinates where r is the sphere's world radius, into view space; call the result point S
  • compute rv = distance from C to S (in view space)
  • let point S1 in view coordinates be C + (rv, 0, 0) - i.e. another point on the surface of the sphere in view space, for which the line C -> S1 is perpendicular to the "look" vector
  • project C and S1 into screen coords using the projection matrix as Cs and S1s
  • compute screen radius = distance between Cs and S1s

But yeah, like Brandorf said, if you can preserve the camera variables, like FOVy, it would be a lot easier. :-)

Update: Here's a more efficient variant on the above: make an inverse of the projection matrix. Use it to transform the viewport edges back into view space. Then you won't have to project every box into screen coordinates.

Even better, do the same with the view matrix and transform the camera frustum back into world space. That would be more efficient for comparing many boxes against; but harder to figure out the math.

这篇关于投影球体的半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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