我在哪里可以找到所有变换矩阵字段的解释? [英] Where can I find an explanation of all transform matrix fields?

查看:141
本文介绍了我在哪里可以找到所有变换矩阵字段的解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在苹果的一些文档中看到,CALayer转换属性背后的矩阵有m14,m21,m22等字段。我还记得大约一两个月前我看过一张解释这些字段的表格。我很难找到它。有人知道来源吗?

I've seen in some document from apple that the matrix behind a CALayer's transform property has fields like m14, m21, m22 and so on. I also remember that I saw a table that explains those fields, about one or two months ago. I had a hard time trying to find it. Anybody knows a source?

推荐答案

那个结构看起来像这样:

That struct looks like this:

struct CATransform3D
{
    CGFloat m11, m12, m13, m14;
    CGFloat m21, m22, m23, m24;
    CGFloat m31, m32, m33, m34;
    CGFloat m41, m42, m43, m44;
};
typedef struct CATransform3D CATransform3D;

这只是一个4x4变换矩阵,用于变换4向量。它可用于表示任意数量的线性变换。请参阅有关此类矩阵的维基百科文章。大多数这些元素无法真正独立解释,但有些可以。例如,m41,m42和m43表示3空间中的平移。因此,例如,如果您将一个点乘以此矩阵:

This is simply a 4x4 transform matrix used to transform 4-vectors. It can be used to represent any number of linear transforms. See this wikipedia article on this type of matrix. Most of those elements can't really be interpreted independantly, but some can. For example m41, m42, and m43 represent a translation in 3-space. So for example if you multiply a point by this matrix:

[ 1  0  0  0 ]
[ 0  1  0  0 ]
[ 0  0  1  0 ]
[ 1  2  3  1 ]

然后它会将该点向1转换为+ X,向+ Y转换2个单位,向+ Z转换3个单位。

Then it will translate that point by 1 toward +X, 2 units toward +Y, and 3 toward +Z.

                   [ 1  0  0  0 ]
[ x  y  z  1 ]  x  [ 0  1  0  0 ]  =  [ x+1  y+2  z+3  1 ]
                   [ 0  0  1  0 ]
                   [ 1  2  3  1 ]

请注意,该点必须表示为4向量,第4个元素为1.另请注意,此向量实际上是矩阵本身,此矩阵的格式与维基百科文章中描述的格式不同关于变换矩阵。这是因为点通常由单个列(4行矩阵)表示,但Apple将它们表示为4列单行矩阵。这意味着您在维基百科文章中看到的任何变换矩阵都需要在iPhone上使用之前进行转置才能使其正常工作。

Note that the point must be represented as a 4 vector with the 4th element being 1. Also note that this vector is actually a matrix itself and the format of this matrix differs from the one described in the wikipedia article on transform matrices. This is because a point is usually represented by a single column, 4 row matrix, however, Apple represents them as 4 column, single row matrices. This means that any transform matrix you see in the wikipedia article needs to be transposed before using it on the iPhone for it to work correctly.

另一个例子是缩放变换:

Another example is a scaling transform:

[ 2  0  0  0 ]
[ 0  2  0  0 ]
[ 0  0  2  0 ]
[ 0  0  0  1 ]

它会使你点的所有坐标加倍,所以(1,2,3)将成为(2,4,6)。其他变换,如旋转和透视投影更难以识别。

It will double all of the coordinates of your point, so (1, 2, 3) will become (2, 4, 6). Other transforms, like rotations and perspective projections are more difficult to recognize on sight.

以下是转换。 Apple提供了一系列实用程序转换来生成这些矩阵,请参阅此链接。他们实际上并没有讨论CATransform3DMakeRotation背后的数学,但此链接确实如此。

Here is more info on transforms from Apple. A bunch of utility transforms are provided by Apple for generating these matrices, see this link. They don't actually discuss the math behind CATransform3DMakeRotation, but this link does.

这篇关于我在哪里可以找到所有变换矩阵字段的解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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