透视变换矩阵的计算 [英] Calculation of a perspective transformation matrix
问题描述
由于在三维空间中的一个点,我如何计算在齐次坐标矩阵,将预计,点到面以Z = D
,这里的原点是中心投影。
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,让我们试着整理了这一点,不断扩大对伊曼纽尔的答案。
OK, let's try to sort this out, expanding on Emmanuel's answer.
假设的,你的观点载体直接沿Z轴,所有维度都必须由视图平面的距离 D
来的比例缩放原以Z
坐标。这比平凡 D / Z
,赠送:
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)
在齐次坐标,它通常以启动与P = [X,Y,Z,W]
,其中W¯¯== 1
和转型因此完成的:
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
结果将有W¯¯!= 1
,并获得真正的三维坐标,我们标准化的同质载体通过将整个事情由它的是W
部分。
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.
所以,我们需要的是给定一个矩阵 [X,Y,Z,1
]为我们提供了 [X * D,Y * D,Z * D,Z]
,即
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 |
曾经归(由 W'分裂==ž
)为您提供了:
[ x * d / z, y * d / z, d, 1 ]
每第一组方程式以上
per the first set of equations above
这篇关于透视变换矩阵的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!