在哪里可以找到所有变换矩阵字段的解释?

发布于 2024-08-01 17:29:31 字数 109 浏览 1 评论 0原文

我在苹果的一些文档中看到,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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

森罗 2024-08-08 17:29:31

该结构如下所示:

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;

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

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

那么它将将该点向 +X 平移 1,向 +Y 平移 2 个单位,向 +Z 平移 3 个单位。

                   [ 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 上使用,才能正常工作。

另一个例子是缩放变换:

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

它将把点的所有坐标加倍,因此 (1, 2, 3) 将变为 (2, 4, 6)。 其他变换,例如旋转和透视投影,在视觉上更难以识别。

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

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;

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 ]

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 ]

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 ]

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.

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.

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