透视变换矩阵的计算
给定 3D 空间中的一个点,如何计算齐次坐标中的矩阵,该矩阵将该点投影到平面 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,让我们尝试解决这个问题,扩展伊曼纽尔的答案。
假设您的视图向量直接沿着 Z 轴,则所有尺寸都必须按视图平面距离
d
与原始z
的比率进行缩放> 协调。这个比率就是 d / z ,给出:在齐次坐标中,通常以 P =
[x, y, z, w]
开头,其中w = = 1
并且转换是这样完成的:结果将是
w != 1
,为了获得真实的 3D 坐标,我们通过将整个向量除以其来标准化齐次向量>w
组件。因此,我们需要的只是一个矩阵,给定
[x, y, z, 1
] 即可得到[x * d, y * d, z * d, z]
,即一旦标准化(除以
w' == z
)即可得到:根据上面的第一组方程
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 originalz
coordinate. That ratio is triviallyd / z
, giving:In homogenous coordinates, it's usual to start with P =
[x, y, z, w]
wherew == 1
and the transformation is done thus:The result will have
w != 1
, and to get the real 3D coordinates we normalise the homogenous vector by dividing the whole thing by itsw
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.which once normalised (by dividing by
w' == z
) gives you:per the first set of equations above
我猜你所说的投影,正如 Beta 所说,存在于以下交点之间:
O(0, 0, 0)
和点P(a, b, c)
要变换的z=d
如果我是对的,那么让我们看看这条线的方程,由矢量积
OP ^ 给出OM = 0
(提醒一下,两个给定点A
和B
之间的直线方程由AB ^ AM = 0
给出code>,其中M(x, y, z)
;这是一个向量乘积,因此都是向量:0
代表空向量,AB
code> 是向量AB
等):有了
z = d
,我们就只有 2 个线性独立方程:所以这个投影将点
P(a , b, c)
变为点P'(ad/c, bd/c, d)
。对于给出的齐次坐标:编辑:我第一个找到的矩阵是:
但它使用
c
这是点P
的坐标!这是无稽之谈,我找不到不使用这些坐标的A
表达式。我可能对齐次坐标还不够熟悉。I guess the projection you mean, as Beta says, consists in the intersection between:
O(0, 0, 0)
and the pointP(a, b, c)
to be transformedz=d
If I'm right, then let's have a look at the equation of this line, given by the vectorial product
OP ^ OM = 0
(let's remind that the equation of a line between 2 given pointsA
andB
is given byAB ^ AM = 0
, withM(x, y, z)
; this is a vectorial product, so all are vectors:0
represents the null vector,AB
is the vectorAB
, etc):With
z = d
, we then have only 2 linearily independent equations:So this projection converts a point
P(a, b, c)
into a pointP'(ad/c, bd/c, d)
. For homogeneous coordinates that gives:EDIT : the matrix I 1st found was:
but it uses
c
which is the a coordinate of the pointP
!! This is nonsense, I couldn't find an expression ofA
that does not use these coordinates. I may not be familiar enough with homogeneous coordinates.齐次变换矩阵为(欧拉横滚-俯仰-偏航):
r1-9 是组合旋转矩阵的元素:Rx*Ry*Rz(计算出来)
dx dy 和 dz 是位移矢量 (d) 元素
px py 和 pz 是透视向量 (p) 元素
sf 是从这里开始的缩放因子
,如果您使用它的倒数,您可以通过输入目标平面的旋转以及它的原点相对于参考平面的位置(保持对于纯运动学,透视向量位于 0 0 0 且 sf=1),您将得到 T->T* = T1。获取 T1^-1(对于运动学,这只是 R'(转置),水平连接 -R'*d,然后垂直连接 0 0 0 1)。
可以有多个平面,例如 a,b,c 作为链,在这种情况下 T1 = Ta*Tb*Tc*...
然后,v(new) = (T1^-1)*v(old),工作完成。
the homogeneous transformation matrix is (Euler roll-pitch-yaw):
r1-9 are the elements of the combined rotation matrix: Rx*Ry*Rz (work it out)
dx dy and dz are displacement vector (d) elements
px py and pz are the perspective vector (p) elements
sf is the scaling factor
from here on, if you use the inverse of this, you get your projection as a perspective in any arbitrary plane by feeding rotations of your target plane, as well as it's position of origin wrt the reference one in (keep perspective vector at 0 0 0 and sf=1 for pure kinematics), you get T->T* = T1. Get T1^-1 (for kinematics, this is simply R' (transposed,), horizontal concatenated by -R'*d, then vertical concatenated simply by 0 0 0 1).
can have multiple planes e.g. a,b,c as a chain, in which case T1 = Ta*Tb*Tc*...
then, v(new) = (T1^-1)*v(old), job done.