伙计们,[在末尾编辑以添加新信息]
我要么无计可施,要么完全缺乏智慧,不确定是哪一个,所以任何帮助都会很可爱……
我在容器视图中有两个视图。每个子视图的状态部分由 CGAffineTransform 定义。将每个“初始”变换称为“M”,然后在某个时间,在任意一系列手势之后,“最终”状态由变换“N”定义。任务是在变换“Q”中提取手势的累积效果,使得:
问:质量管理-> N
所以我认为
QM(M_Inverse) -> N(M_Inverse)
即Q = N(M_Inverse),问题已解决[NOT]。
用最简单的情况测试了下面的简单代码(现在充满了 nslogs)(XY 中的翻译同样适用于两个子视图(这并不重要,因为这里的一切都是关于转换的,但无论如何)。
- (void) saveLastTransform:(BOOL)returnA {
if (returnA) {
helper.xformLastA = CGAffineTransformIdentity;
if (svDelegate.isAlignmentActivated) {
if ((int)(100.0 * helper.xformDefaultA.a) != 0) {
NSLog(@"AM = %f, %f, %f", helper.xformDefaultA.a, helper.xformDefaultA.b, helper.xformDefaultA.tx);
NSLog(@" %f, %f, %f", helper.xformDefaultA.c, helper.xformDefaultA.d, helper.xformDefaultA.ty);
CGAffineTransform defInvA = CGAffineTransformInvert(helper.xformDefaultA);
NSLog(@"AM_1 = %f, %f, %f", defInvA.a, defInvA.b, defInvA.tx);
NSLog(@" %f, %f, %f", defInvA.c, defInvA.d, defInvA.ty);
CGAffineTransform defInvAInv = CGAffineTransformInvert(defInvA);
NSLog(@"AM_1_1 = %f, %f, %f", defInvAInv.a, defInvAInv.b, defInvAInv.tx);
NSLog(@" %f, %f, %f", defInvAInv.c, defInvAInv.d, defInvAInv.ty);
CGAffineTransform ident = CGAffineTransformConcat(defInvA, helper.xformDefaultA);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
ident = CGAffineTransformConcat(defInvA, defInvAInv);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
ident = CGAffineTransformConcat(defInvAInv, defInvA);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
helper.xformLastA = CGAffineTransformConcat([self getActiveTransform:groupA], defInvA);
CGAffineTransform N = [self getActiveTransform:groupA];
NSLog(@"AN = %f, %f, %f", N.a, N.b, N.tx);
NSLog(@" %f, %f, %f", N.c, N.d, N.ty);
NSLog(@"AQ = %f, %f, %f", helper.xformLastA.a, helper.xformLastA.b, helper.xformLastA.tx);
NSLog(@" %f, %f, %f", helper.xformLastA.c, helper.xformLastA.d, helper.xformLastA.ty);
}
}
}
else {
helper.xformLastB = CGAffineTransformIdentity;
if (svDelegate.isAlignmentActivated) {
if ((int)(100.0 * helper.xformDefaultB.a) != 0) {
NSLog(@"BM = %f, %f, %f", helper.xformDefaultB.a, helper.xformDefaultB.b, helper.xformDefaultB.tx);
NSLog(@" %f, %f, %f", helper.xformDefaultB.c, helper.xformDefaultB.d, helper.xformDefaultB.ty);
CGAffineTransform defInvB = CGAffineTransformInvert(helper.xformDefaultB);
NSLog(@"BM_1 = %f, %f, %f", defInvB.a, defInvB.b, defInvB.tx);
NSLog(@" %f, %f, %f", defInvB.c, defInvB.d, defInvB.ty);
CGAffineTransform defInvBInv = CGAffineTransformInvert(defInvB);
NSLog(@"BM_1_1 = %f, %f, %f", defInvBInv.a, defInvBInv.b, defInvBInv.tx);
NSLog(@" %f, %f, %f", defInvBInv.c, defInvBInv.d, defInvBInv.ty);
CGAffineTransform ident = CGAffineTransformConcat(defInvB, helper.xformDefaultB);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
ident = CGAffineTransformConcat(defInvB, defInvBInv);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
ident = CGAffineTransformConcat(defInvBInv, defInvB);
NSLog(@"Identity? = %f, %f, %f", ident.a, ident.b, ident.tx);
NSLog(@" %f, %f, %f", ident.c, ident.d, ident.ty);
helper.xformLastB = CGAffineTransformConcat([self getActiveTransform:groupB], defInvB);
CGAffineTransform N = [self getActiveTransform:groupB];
NSLog(@"BN = %f, %f, %f", N.a, N.b, N.tx);
NSLog(@" %f, %f, %f", N.c, N.d, N.ty);
NSLog(@"BQ = %f, %f, %f", helper.xformLastB.a, helper.xformLastB.b, helper.xformLastB.tx);
NSLog(@" %f, %f, %f", helper.xformLastB.c, helper.xformLastB.d, helper.xformLastB.ty);
}
}
}
}
如果您查看源矩阵(AM 和 BM),您可以“看到”每个集合(AN 和 BN)的翻译是相同的,但第二种情况的逆计算很奇怪……无论是手动还是使用方便的网站: http: //www.bluebit.gr/matrix-calculator/我看不出这是一个有效的逆(并且计算出的 Q 反映了这一事实)。
Output
变换“A”
2013-05-17 13:19:18.349 affinetest [16929:
707
]
13:19:18.355 AffineTest[16929:707] AM_1 = 1.006434, 0.003925, -54.921101
2013-05-17 13:19:18.359 AffineTest[16929:707] -0.005988, 1.00176574,
-197-58808-297-28 :18.371 AffineTest[16929:707] AM_1_1 = 0.993584, -0.003874, 54.730003
2013-05-17 13:19:18.375 AffineTest[16929:707] 0.005911, 0.993446, 26.889999
2013-05-17 13:19:18.379 AffineTest[16929 :707] 身份?= 1.000000, 0.000000, -0.000002
2013-05-17 13:19:18.383 AffineTest[16929:707] 0.000000, 1.000000, -0.000001
2013-05-17 13:19:18.386 AffineTest [16929:707] 身份?= 1.000000, 0.000000, 0.000002
2013-05-17 13:19:18.390 AffineTest[16929:707] 0.000000, 1.000000, -0.000001
2013-05-17 13:19:1698.3907] 仿射测试[16929:707] = 1.000000, -0.000000, 0.000001
2013-05-17 13:19:18.397 AffineTest[16929:707] -0.000000, 1.000000, -0.000000
2013-05-17 13:19:18.401 AffineTest[16929:707] AN = 0.993584, -0.003874,308.729980
2013-05-17 13:19:19:18.405 affInetest [16929:707] 0.005911,0.993446,220.889999 2013-05-17 2013-17 2013-17
13:19:19:18.408 affinetest [18.408 affinetest
] -05-17 13:19:18.411 仿射测试[16929:707] -0.000000, 1.000000, 196.272278
变换“B”
2013-05-17 13:19:18.415 AffineTest[16929:707] BM = 0.753817, 0.038102, 344.529999
2013-05-17 13:19:18.419 AffineTest[16929:707] -0.041526, 0.740303, 152.130005
2013-05-17 13:19:18.422 AffineTest[16929:707] BM_1 = 1.322831, -0.068084, -467.043274
2013-05-17 13:19:18.425 AffineTest[16929:707] 0.074201, 1.346979, -181.458923
2013-05-17 13:19 :18.429 affinetest [16929:707] BM_1_1 = 0.753817,0.038102,344.530029
2013-05-17 13:19:19:18.432 affinetestest [16929:707
] :707] 身份?= 1.000000, -0.000000, -0.000008
2013-05-17 13:19:18.439 AffineTest[16929:707] -0.000000, 1.000000, 0.000003
2013-05-17 13:19:18.442 AffineTest [16929:707] 身份?= 1.000000, -0.000000, -0.000005
2013-05-17 13:19:18.446 AffineTest[16929:707] 0.000000, 1.000000, 0.000003
2013-05-17 13:19:1698.449 AffineTest[7] = 1.000000, -0.000000, 0.000012
2013-05-17 13:19:18.452 AffineTest[16929:707] 0.000000, 1.000000, 0.000007
2013-05-17 13:19:18.456 AffineTest[16929:707] BN = 0.753817, 0.038102, 598.530029
2013-05-17 13:19:18.459 AffineTest[16929:707] -0.041526, 0.740303, 346.130005
2013-05-17 13:19:18.463 AffineTest[16929:707] BQ = 1.000000, 0.000000, 350.394165
2013-05- 17 13:19:18.466 仿射测试 [16929:707] 0.000000、1.000000、244.020630
然而,多次反转恢复了原始变换,iOS 说它们是真正的反转。有人可以告诉我我在这里缺少什么[显而易见的闪光]?谢谢!
编辑。
原来这是由于 iOS 约定 x' = xT 而不是 Tx 所以矩阵是
|ab 0|
|cd 0|
|tx ty 1|
而不是通常的约定
|ab tx|
|cd ty|
|0 0 1|
所以传统的矩阵代数似乎不适用。如果我在第二种情况下跟随链条(使用外部工具),我会得到:
M矩阵:
0.754 0.038 344.530
-0.042 0.740 152.130
0.000 0.000 1.000
M 逆:
1.322 -0.068 -445.302
0.075 1.347 -230.855
0.000 0.000 1.000
N 矩阵
0.754 0.038 598.530
-0.042 0.740 346.130
0.000 0.000 1.000
Q 矩阵 = N x M 逆 [正确平移]
0.999 0.000 254.058
0.001 1.000 193.719
0.000 0.000 1.000
但是使用 iOS 表单你会得到:
M矩阵:
0.754 0.038 0.000
-0.042 0.740 0.000
344.530 152.130 1.000
M 逆:1.323 -0.068 0.000
0.074 1.347 0.000
-467.043 -181.459 1.000
N 矩阵:0.754 0.038 0.000
-0.042 0.740 0.000
598.530 346.130 1.000
Q 矩阵 = N x M 逆 [错误翻译]
1.000 0.000 0.000
0.000 1.000 0.000
350.426 244.078 1.000
但是 Q' = M-Inverse x N [正确???翻译]
1.000 0.000 0.000
-0.001 1.000 0.000
254.001 194.103 1.000
这似乎太错误了——这到底是怎么回事。是否存在另一个宇宙,这在[数学上]有意义???