title: Transforming a rectangle image into a quadrilateral using a CATransform3D
body: <p>I have an image and a set of four points (describing a quadrilateral Q). I want to transform this image so that it is fits the quadrilateral Q. Photoshop calls this transformation "Distort." But according to the source of this quadrilateral (the perspective of the image moving in space), it is in fact the combination of a scale, a rotation and a perspective matrix.</p>
  
  <p>I am wondering if this is possible using a CATransform3D 4x4 matrix. Do you have any hints on how to do that? I've tried to take the four points and build 16 equations (out of A' = A x u) but it did not work: I'm not sure of what I should use as z, z', w and w' coefficients…</p>
  
  <p>The following picture shows what I want to do:</p>
  
  <p><img src="https://i.stack.imgur.com/el5TF.jpg" alt="Transforming a rectangle image into a quadrilateral using a CATransform3D"></p>
  
  <p>Here are some examples of points:</p>
  
  <pre><code>276.523, 236.438,   517.656, 208.945,   275.984, 331.285,   502.23,  292.344
  261.441, 235.059,   515.09,  211.5,     263.555, 327.066,   500.734, 295
  229.031, 161.277,   427.125, 192.562,   229.16, 226,        416.48,  256
  </code></pre>