仿射变换
我正在尝试解决以下问题。我对仿射变换了解不多。有人可以帮我回答这个问题吗:
找到一个 3x3 矩阵,表示齐次坐标的 2D 仿射变换(即每个点 [x,y]
表示为列向量 [x, y, 1]
),将正方形 [0,0],[1,0],[1,1],[0,1]
转换为平行四边形 [0 ,1],[1,1],[2,2],[1,2]
。
I am trying to solve the below problem. I don't have much knowledge in Affine transformations. Could someone help me answer this question:
Find a 3x3 matrix representing a 2D affine transformation of homogeneous coordinates (i.e. every point [x,y]
is represented as a column vector [x, y, 1]
), which transforms a square [0,0],[1,0],[1,1],[0,1]
into a parallelogram [0,1],[1,1],[2,2],[1,2]
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
关于这个问题我发现的事情
1)您需要了解同质坐标
2) 您需要了解行专业和列专业之间的区别 - 阅读此处
3)您需要了解基本的仿射变换 - 旋转、缩放/剪切和平移以及如何在矩阵中表示它们 - 阅读此页
有趣的是,我认为答案只需要平移和剪切(无需旋转)。
查看源点和目标点,看起来所有目标点都在 y 中平移 +1,并在 X 中剪切 1(为了给出平行四边形,可能最好将其画出来看看我的意思)
所以从 3 * 开始3 单位矩阵 为
1 0 0
0 1 0
0 0 1
剪力将是
1 1 0
0 1 0
0 0 1
翻译将是
1 0 0
0 1 1
0 0 1
所以把它们放在一起应该是
1 1 0
0 1 1
0 0 1
我通常不使用列专业,所以可能值得仔细检查!
希望有帮助
Things I spotted about this question
1) You need to understand homogeneous co-ordinates
2) You need to know the difference between row and column major - read here
3) You need to know the basic affine transformations - rotate, scale/shear and translate and how to represent them in a matrix - read this page
Interestingly, I think the answer only needs a translate and a shear ( no rotation ).
Looking at the source and dest points, it looks like all dest points are translated +1 in y and sheared by 1 in X ( to give the parallelogram, probably best to draw it out to see what I mean )
So start with a 3 * 3 identity matrix which is
1 0 0
0 1 0
0 0 1
The shear will be
1 1 0
0 1 0
0 0 1
The translate will be
1 0 0
0 1 1
0 0 1
So putting it all together should be
1 1 0
0 1 1
0 0 1
I don't normally use column major so probably worth double checking!
Hope that helps
仿射变换是 x ⟼ Ax + b 形式的变换,其中 x 和 b 是向量,A 是方阵。在几何上,仿射变换将平行四边形映射到平行四边形并保留沿线的相对距离。
为了解决这样的问题,我们首先注意到对于原点,我们有 0 ⟼ A0 + b = b。由于问题告诉我们 [0,0] ⟼ [0,1],所以我们知道 b = [0,1]。
接下来,我们从线性代数中回忆一下,将矩阵乘以标准基向量 [0,1] 和 [1,0] 只是分别提取矩阵的第一列和第二列:
我们得到 [1,0] ⟼ [ 1,1] 和 [0,1] ⟼ [1,2]。由此我们得到
这给了我们仿射变换
齐次坐标是一个技巧,它让我们将仿射变换写成矩阵,只是有一个总是设置为1的额外坐标。矩阵公式是
这里A实际上是一个2×2矩阵,而b和x是2向量,左下角的0实际上是[0 0]。总的来说,我们正在处理一个 3×3 矩阵和 3 个向量。
所以我们的解决方案是
,为了更好地衡量,我们检查它是否能正常工作以实现最后一点:
An affine transformation is a transformation of the form x ⟼ Ax + b, where x and b are vectors, and A is a square matrix. Geometrically, affine transformations map parallelograms to parallelograms and preserve relative distances along lines.
To solve a problem like this, we first note that for the origin, we have 0 ⟼ A0 + b = b. Since the problem tells us that [0,0] ⟼ [0,1], we know that b = [0,1].
Next we recall from linear algebra that multiplying a matrix by the standard basis vectors [0,1] and [1,0] simply extracts the first and second columns of the matrix, respectively:
We are given that [1,0] ⟼ [1,1] and [0,1] ⟼ [1,2]. From this we obtain
This gives us our affine transformation
Homogeneous coordinates are a trick which let us write affine transformations as matrices, just with one extra coordinate that is always set to 1. The matrix formula is
Here A is actually a 2×2 matrix, while b and x are 2-vectors, and the 0 in the bottom left is really [0 0]. So overall, we are dealing with a 3×3 matrix and 3-vectors.
So our solution is
and for good measure we check that it works properly for the final point:
当然,您已经阅读过有关该主题的维基百科页面。
很久以前,我读过Foley 和 van Dam之前版本的版本(这可能是 1983 年或 1984 年),它涵盖了使用问题中描述的增强矩阵和向量操作 2D 和 3D 坐标的技术。然而,从那时起已经过去了足够的时间,我已经忘记了所有的细节(并且不再有这本书——太多的房子搬家了)。我好像记得还有一本纽曼和斯普劳尔写的书。
B 的列代表正方形的角; C 的列代表平行四边形的角;并且必须求解矩阵方程 A x B = C。 IIRC,矩阵A右下角有一个1;值 c、f、g 和 h 也可能具有预定值(它们可能为零)。非零值应用线性(仿射)变换、缩放、剪切和旋转输入形状。
您需要在教科书中查找类似的信息。或者在维基页面中 - 我没有仔细看它(上面的信息是从古代记忆中得出的)。
You'll have read the Wikipedia page on the subject, of course.
Once upon an aeon or so ago, I read Foley and van Dam in one of the predecessor versions (this would have been 1983 or 1984), and it covered techniques for manipulating 2D and 3D coordinates with augmented matrices and vectors as described in the question. However, enough time has lapsed since then that I've forgotten all the details (and no longer have the book--too many moves of house). There was also a book by Newman and Sproul, I seem to remember.
The columns of B represent the corners of the square; the columns of C represent the corners of the parallelogram; and the matrix equation A x B = C has to be solved. IIRC, the matrix A has a 1 in the bottom right corner; it is possible that the values c, f, g, and h also have presecribed values (they'd probably be zeroes). The non-zero values apply a linear (affine) transform, scaling, shearing and rotating the input shape.
You'd need to look for similar information in a text book. Or in the Wiki page - I didn't look hard at it (the information above is working from ancient memory).
我只是想指出超过四个点限制了二维仿射变换。在 Jonathan Leffler 的评论中,您可以从需要反转非方矩阵的事实中看出这一点。因此,要么选择其中的三个点,要么建立一个最小二乘系统。过度约束的最小二乘解可以用以下矩阵求解,
以便使用正规方程求解可以
撤销转置给出的结果
I just wanted to point out that four points over constrain a 2D affine transformation. In the comment of Jonathan Leffler, you can see this from the fact that you would need to invert a non-square matrix. So, either choose three of the points or set up a least-squares system. The over-constrained, least-squares solution could be solved with the following matrices
so that solving using the normal equations gives
undoing that transpose gives