透视变换矩阵的计算 [英] Calculation of a perspective transformation matrix

查看:128
本文介绍了透视变换矩阵的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定 3D 空间中的一个点,我如何计算齐次坐标中的矩阵,该矩阵将该点投影到平面 z == d,其中原点是投影中心.>

解决方案

好的,让我们试着解决这个问题,扩展 Emmanuel 的答案.

假设你的视图向量直接沿着Z轴,所有的维度都必须按视图平面距离d与原始z的比例缩放 坐标.这个比率是微不足道的d/z,给出:

x' = x * (d/z)y' = y * (d/z)z' = z * (d/z) ( = d)

在齐次坐标中,通常以 P = [x, y, z, w] 开头,其中 w == 1 并且转换是这样完成的:

P' = M * P

结果将有 w != 1,为了获得真实的 3D 坐标,我们通过将整个事物除以其 w 分量来标准化齐次向量.>

所以,我们只需要一个矩阵,给定 [x, y, z, 1] 给我们 [x * d, y * d, z * d, z],即

<代码>|x' |= |d 0 0 0 |* |× ||y' |= |0 d 0 0 |* |是 ||z' |= |0 0 d 0 |* || ||w' |= |0 0 1 0 |* |1 |

一旦标准化(通过除以 w' == z)给你:

[ x * d/z, y * d/z, d, 1 ]

根据上面的第一组方程

Given a point in 3D space, how can I calculate a matrix in homogeneous coordinates which will project that point into the plane z == d, where the origin is the centre of projection.

解决方案

OK, let's try to sort this out, expanding on Emmanuel's answer.

Assuming that your view vector is directly along the Z axis, all dimensions must be scaled by the ratio of the view plane distance d to the original z coordinate. That ratio is trivially d / z, giving:

x' = x * (d / z)
y' = y * (d / z)
z' = z * (d / z)    ( = d)

In homogenous coordinates, it's usual to start with P = [x, y, z, w] where w == 1 and the transformation is done thus:

P' = M * P

The result will have w != 1, and to get the real 3D coordinates we normalise the homogenous vector by dividing the whole thing by its w component.

So, all we need is a matrix that given [x, y, z, 1] gives us [x * d, y * d, z * d, z], i.e.

| x' |  =    | d   0   0   0 |  *  | x |
| y' |  =    | 0   d   0   0 |  *  | y |
| z' |  =    | 0   0   d   0 |  *  | z |
| w' |  =    | 0   0   1   0 |  *  | 1 |

which once normalised (by dividing by w' == z) gives you:

[ x * d / z, y * d / z,   d,   1 ]

per the first set of equations above

这篇关于透视变换矩阵的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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