这似乎不可能,我确信有一个简单的解决方案,但我无法解决。我的高中矩阵数学有点生疏:)
我正在构建一个CGAffineTransform
对 a 进行平移-旋转-平移,CGRect
然后尝试使用逆CGAffineTransformInvert返回到原始位置。但事实并非如此。我已经设法减少到这个:
// start building the transform...
// translate so (0,0) is at centre of image
CGAffineTransform affine = CGAffineTransformMakeTranslation(-100, -100);
// add a rotate
affine = CGAffineTransformConcat(affine, CGAffineTransformMakeRotation(M_PI/4));
// get the inverse
CGAffineTransform inverseAffine = CGAffineTransformInvert(affine);
// now test this: pick a starting CGRect
CGRect start = CGRectMake(50, 40, 10, 20);
// use my CGAffineTransform to move "start" to "midpoint"
CGRect midpoint = CGRectApplyAffineTransform(start, affine);
// use the inverse to move "midpoint" to "finish"
CGRect finish = CGRectApplyAffineTransform(midpoint, inverseAffine);
// what did we get
NSLog(@"start %5.1f %5.1f %5.1f %5.1f", start.origin.x, start.origin.y, start.size.width, start.size.height);
NSLog(@"midpoint %5.1f %5.1f %5.1f %5.1f", midpoint.origin.x, midpoint.origin.y, midpoint.size.width, midpoint.size.height);
NSLog(@"finish %5.1f %5.1f %5.1f %5.1f", finish.origin.x, finish.origin.y, finish.size.width, finish.size.height);
输出如下所示:
2011-09-29 ... start 50.0 40.0 10.0 20.0
2011-09-29 ... midpoint -7.1 -77.8 21.2 21.2
2011-09-29 ... finish 40.0 35.0 30.0 30.0
结束矩形不应该与开始相同吗?这不CGAffineTransformInvert
就是应该做的吗?
如果我做同样的事情但用 aCGPoint
而不是 aCGRect
它似乎工作正常。