透视变换矩阵的计算

发布于 2024-10-21 02:39:14 字数 65 浏览 1 评论 0原文

给定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遮了一弯 2024-10-28 02:39:14

好吧,让我们尝试解决这个问题,扩展伊曼纽尔的答案。

假设您的视图向量直接沿着 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 |  *  | x |
| y' |  =    | 0   d   0   0 |  *  | y |
| z' |  =    | 0   0   d   0 |  *  | z |
| w' |  =    | 0   0   1   0 |  *  | 1 |

一旦标准化(除以 w' == z)即可得到:

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

根据上面的第一组方程

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

傻比既视感 2024-10-28 02:39:14

我猜你所说的投影,正如 Beta 所说,存在于以下交点之间:

  • 由原点 O(0, 0, 0) 和点 P(a, b, c) 要变换的
  • 平面 z=d

如果我是对的,那么让我们看看这条线的方程,由矢量积 OP ^ 给出OM = 0(提醒一下,两个给定点 AB 之间的直线方程由 AB ^ AM = 0 给出code>,其中 M(x, y, z);这是一个向量乘积,因此都是向量:0 代表空向量,AB code> 是向量 AB 等):

bz - cy = 0
cx - az = 0
cz - bx = 0

有了 z = d,我们就只有 2 个线性独立方程:

bd = cy
cx = ad

所以这个投影将点 P(a , b, c) 变为点 P'(ad/c, bd/c, d)。对于给出的齐次坐标:

P'(ad/c, bd/c, d) = P'(ad/c, bd/c, cd/c)
                  = P'(ad/c: bd/c: cd/c: 1)
                  = P'(a: b: c: d/c)

编辑:我第一个找到的矩阵是:

    1, 0, 0, 0
    0, 1, 0, 0
A = 0, 0, 1, 0
    0, 0, 0, d/c

但它使用 c 这是点 P 的坐标!这是无稽之谈,我找不到不使用这些坐标的 A 表达式。我可能对齐次坐标还不够熟悉。

I guess the projection you mean, as Beta says, consists in the intersection between:

  • the line formed by the origin O(0, 0, 0) and the point P(a, b, c) to be transformed
  • and the plane z=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 points A and B is given by AB ^ AM = 0, with M(x, y, z); this is a vectorial product, so all are vectors: 0 represents the null vector, AB is the vector AB, etc):

bz - cy = 0
cx - az = 0
cz - bx = 0

With z = d, we then have only 2 linearily independent equations:

bd = cy
cx = ad

So this projection converts a point P(a, b, c) into a point P'(ad/c, bd/c, d). For homogeneous coordinates that gives:

P'(ad/c, bd/c, d) = P'(ad/c, bd/c, cd/c)
                  = P'(ad/c: bd/c: cd/c: 1)
                  = P'(a: b: c: d/c)

EDIT : the matrix I 1st found was:

    1, 0, 0, 0
    0, 1, 0, 0
A = 0, 0, 1, 0
    0, 0, 0, d/c

but it uses c which is the a coordinate of the point P !! This is nonsense, I couldn't find an expression of A that does not use these coordinates. I may not be familiar enough with homogeneous coordinates.

丘比特射中我 2024-10-28 02:39:14

齐次变换矩阵为(欧拉横滚-俯仰-偏航):

|r1 r2 r3 dx|
|r4 r5 r6 dy|
|r7 r8 r9 dz|
|px py pz sf|

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 r2 r3 dx|
|r4 r5 r6 dy|
|r7 r8 r9 dz|
|px py pz sf|

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文