Re: Coordinate conversions in CALayer
Re: Coordinate conversions in CALayer
- Subject: Re: Coordinate conversions in CALayer
- From: James Montgomerie <email@hidden>
- Date: Thu, 24 Jan 2013 09:26:20 +0000
On 24 Jan 2013, at 08:19, Graham Cox <email@hidden> wrote:
> I've made some progress, in that I managed to make the two code snippets work the same, by changing this line:
>
> tfm = CGAffineTransformConcat( tfm, layer.transform );
>
> to this:
>
> tfm = CGAffineTransformConcat( layer.transform, tfm );
>
> I do appreciate that matrix concatenation isn't commutative, but it's still not clear to me why it needs to be this way round when the equivalent line when manipulating the CTM is:
>
> CGContextConcatCTM( ctx, layer.transform );
>
> This suggests that internally, this call passes the CTM as the second parameter, not the first. If so, then the documentation could do well to spell that out, since matrix order is so important. If not, then my understanding is still off, which does not surprise me.
I looked this up again, because it's hit me in the past - it feels unintuitive to me half the times I use it too, but it is actually spelled out in the docs:
------
CGContextConcatCTM (http://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html):
Transforms the user coordinate system in a context using a specified matrix.
void CGContextConcatCTM(CGContextRef c, CGAffineTransform transform);
...
Discussion: When you call the function CGContextConcatCTM, it concatenates (that is, it combines) two matrices, by multiplying them together. The order in which matrices are concatenated is important, as the operations are not commutative. When you call CGContextConcatCTM, the resulting CTM in the context is: CTMnew = transform * CTMcontext.
------
CGAffineTransformConcat (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html):
Returns an affine transformation matrix constructed by combining two existing affine transforms.
CGAffineTransform CGAffineTransformConcat(CGAffineTransform t1, CGAffineTransform t2);
...
Return Value: A new affine transformation matrix. That is, t’ = t1*t2.
------
Jamie.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden