Question

You can probably see where I am going with this - but is there any easy way to generate a CGAffineTransform from two lines - each represented by a pair of CGPoints:

A[(a1x,a1y), (a2x,a2y)],
B[(b1x,b1y), (b2x,b2y)]

The resultant CGAffineTransform when applied to line A would of course produce line B. It potentially could involve a translation, scale, and rotation.

Certainly I would hope to be able to write this myself after brushing up on some trig but I was wondering if anything is already available to do this?

Note: I am not asking you to write this for me - I just don't want to miss a Core Graphics trick!

Was it helpful?

Solution

Yes, but there are at least four solutions: two translations and two scales (one per operation and direction). That's without counting transformations that both translate and scale.

“The Math Behind the Matrices”, from the Quartz 2D Programming Guide, is a good overview of how each operation works; from that, it should be simple enough to invert it and come up with a matrix for the desired operation and direction.

Certainly I would hope to be able to write this myself after brushing up on some trig…

You won't need that except for rotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top