gpt4 book ai didi

c# - 从初始和结果二维矩阵计算二维变换矩阵

转载 作者:太空狗 更新时间:2023-10-29 23:18:32 26 4
gpt4 key购买 nike

在编程方面,我绝不自称是天才,我目前的问题让我很困惑。

我找到了这个问题Trying to derive a 2D transformation matrix using only the images这似乎至少部分回答了我的问题,但应该显示解决方案的图像不再可用:S

我在 C# 中工作而不使用 WPF,因为我的输入或输出都不需要以图形方式显示。

在我的程序中我有 2 个四边形,我们称它们为输入四边形和输出四边形。

输入四边形的坐标从左下角顺时针方向为 (2,1),(2,3),(4,4),(3,1)。

输出四边形可以有任何坐标,并将再次从左下顺时针顺序列出。

给定这 8 个坐标对,是否可以计算出可以应用于任何单个坐标对的变换矩阵?

我不太热衷于矩阵,但如果指向正确的方向,我愿意学习。

非常感谢

乔希

最佳答案

快速谷歌或跳跃、跳过并找到谷歌 this .我认为它一定会解决您的问题。

正如我在评论中提到的,您要求同构函数将四边形内的单个点投影到第二个四边形中的点。我没有手动计算,而是找到了以下算法。

在这里发布算法以供后代使用:

Let p00, p10, p11,and p01 be the vertices of the first quadrilateral listed in counterclockwise order.

Let q00, q10, q11,and q01 be the vertices of the second quadrilateral listed in counterclockwise order.

Define P10 = p10-p00, P11 = p11-p00, P01 = p01-p00, Q10 = q10-q00, Q11 = q11-q00, and Q01 = q01-q00.

Compute a and b so that Q11 = aQ10 + bQ01.

This is a set of two linear equations in two unknowns.

Similarly, compute c and d so that P11 = cP10 + dP01.

It turns out that a >= 0, b >= 0, a + b> 1, c >= 0, d >= 0,and c + d> 1.

Any point p in the quadrilateral can be written as p =(1-x-y)p00 + xp10 + yp01 where x = 0, y = 0,(1 - d)x + c(y - 1) = 0, and d(x - 1)+(1 - c)y = 0.

Any point q in the quadrilateral can be written as q =(1-u-v)q00 + uq10 + vq01 where u = 0, v = 0,(1 - b)u + a(v -1) = 0, and b(u - 1) + (1 - a)v = 0.

The perspective mapping relating (u,v) to (x,y) is u = m0x n0 + n1x + n2y and v = m1y n0 + n1x + n2y where m0 = ad(1 - c - d), m1 = bc(1 - c - d), n0 = cd(1 - a - b), n1 = d(a - c + bc - ad),and n2 = c(b - d - bc + ad).

Effectively the p-quadrilateral is mapped to a “standard” one, <(0, 0),(1, 0),(0, 1),(c,d)>

and the q-quadrilateral is mapped to <(0, 0),(1, 0), (0, 1), (a,b)>.

The (x,y) to (u,v) mapping relates these two.

You can verify that

• (x,y)=(0, 0) is mapped to (u,v)=(0, 0)

• (x,y)=(1, 0) is mapped to (u,v)=(1, 0)

• (x,y)=(0, 1) is mapped to (u,v)=(0, 1)

• (x,y)=(c,d) is mapped to (u,v)=(a,b)

我将给出另一个答案,描述我将如何解决评论中的示例 - 这个答案太长了。

关于c# - 从初始和结果二维矩阵计算二维变换矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4857227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com