org.freedesktop.cairo

## Class Matrix

- Object
- - org.freedesktop.bindings.Pointer
  - - org.freedesktop.bindings.Proxy
    - - org.freedesktop.cairo.Matrix

-     public class Matrix
      extends org.freedesktop.bindings.Proxy

  A matrix describing an affine transformation.

  You can apply this transformation to a Cairo Context with its `transform()` method as follows:

       matrix = new Matrix();
       matrix.rotate(...);    // and/or
       matrix.scale(...);     // and/or
       matrix.translate(...);

       cr.transform(matrix);

  Calls to the `rotate()`, `scale()`, and `translate` methods are cumulative on a given Matrix.

  Applying a transformation is what take you from device co-ordinates to user-space co-ordinates; you are in fact always working in the later but we tend not to focus on this as the default is naturally no transformation.

  ## Examples

  In each of the illustrations below, we draw a box as follows:

       cr.setSource(0.7, 0.8, 0.8);
       cr.rectangle(5, 5, 25, 15);
       cr.stroke();

  We then apply the transform shown, change colour to blue, and then draw the exact same rectangle again:

       cr.setSource(0.0, 0.0, 1.0);
       cr.rectangle(5, 5, 25, 15);
       cr.stroke();

  Thus both the original rectangle and the result of the matrix operation are shown.
  Since:
    4.0.10
  Author:
    Andrew Cowie

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Matrix()` Construct a new transformation matrix with the identity (no-op) transform.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `rotate(double angle)` Rotate the transformation by the given angle.
    `void` | `scale(double sx, double sy)` Scale by `sx` horizontally and `sy` vertically.
    `void` | `translate(double tx, double ty)` Translate by `tx` horizontally and `ty` vertically.

    - ### Methods inherited from class org.freedesktop.bindings.Pointer

      `toString`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Matrix

          public Matrix()

      Construct a new transformation matrix with the identity (no-op) transform.
      Since:
        4.0.10

  - ### Method Detail

    - #### rotate

          public void rotate(double angle)

      Rotate the transformation by the given angle. As with elsewhere in Cairo, `angle` is in radians.

           matrix.rotate(-Math.PI / 4.0);
           cr.transform(matrix);

      A negative angle is used in this example for the same reason as discussed in `arc()`.

      Since:
        4.0.10

    - #### scale

          public void scale(double sx,
                   double sy)

      Scale by `sx` horizontally and `sy` vertically.

           matrix.scale(-0.8, 1.6);
           cr.transform(matrix);

      Note that in this example the `sx` argument being negative results in a reflection through the y axis. Note also that the line widths are not the same as the original image's were; only scaling by `1.0` would have left the widths alone.

      Don't scale by `0`.

      Since:
        4.0.10

    - #### translate

          public void translate(double tx,
                       double ty)

      Translate by `tx` horizontally and `ty` vertically.

           matrix.translate(5, 10);
           cr.transform(matrix);

      Since:
        4.0.10