Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A little bit of matrix algebra and trigonometric identities can help you solve this.</p> <p>We'll work forward to generate a matrix that scales and rotates, and then use that to figure out how to extract the scale factors and rotations analytically.</p> <p>A scaling matrix to scale by Sx (in the X axis) and Sy (in the Y axis) looks like this:</p> <pre><code>⎡Sx 0 ⎤ ⎣0 Sy⎦ </code></pre> <p>A matrix to rotate clockwise by R radians looks like this:</p> <pre><code>⎡cos(R) sin(R)⎤ ⎣-sin(R) cos(R)⎦ </code></pre> <p>Using standard matrix multiplication, the combined scaling and rotation matrix will look like this:</p> <pre><code>⎡Sx.cos(R) Sx.sin(R)⎤ ⎣-Sy.sin(R) Sy.cos(R)⎦ </code></pre> <p>Note that linear transformations could also include shearing or other transformations, but I'll assume for this question that only rotation and scaling have occurred (if a shear transform is in the matrix, you will get inconsistent results from following the algebra here; but the same approach can be used to determine an analytical solution).</p> <p>A <a href="http://developer.apple.com/iPhone/library/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/doc/uid/TP30000946-CH2g-C016165" rel="noreferrer">CGAffineTransform</a> has four members a, b, c, d, corresponding to the 2-dimensional matrix:</p> <pre><code>⎡a b⎤ ⎣c d⎦ </code></pre> <p>Now we want to extract from this matrix the values of Sx, Sy, and R. We can use a simple trigonometric identity here:</p> <pre><code>tan(A) = sin(A) / cos(A) </code></pre> <p>We can use this with the first row of the matrix to conclude that:</p> <pre><code>tan(R) = Sx.sin(R) / Sx.cos(R) = b / a and therefore R = atan(b / a) </code></pre> <p>And now we know R, we can extract the scale factors by using the main diagonal:</p> <pre><code>a = Sx.cos(R) and therefore Sx = a / cos(R) d = Sy.cos(R) and therefore Sy = d / cos(R) </code></pre> <p>So you now know Sx, Sy, and R.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload