Sgss_Graphics_Transform
Represents a two-dimensional affine transformation matrix

Description

Implements:
ArrayAccess (internal interface), Sgss_Graphics_Imagick_Get_Interface, Sgss_Graphics_Imagick_Draw_Interface
Author:
Matsuda Shota
Copyright:
(c) 2007-2008 Matsuda Shota
License:
http://creativecommons.org/licenses/GPL/2.0/
Located in:
/Graphics/Transform.php (line 69)

Class overview

Accessors

number $sx

Scaling x element

number $rx

Shearing x element

number $tx

Translation x element

number $ry

Shearing y element

number $sy

Scaling y element

number $ty

Translation y element

Variables

protected number $_rx

Shearing x element

protected number $_ry

Shearing y element

protected number $_sx

Scaling x element

protected number $_sy

Scaling y element

protected number $_tx

Translation x element

protected number $_ty

Translation y element

Methods

__construct ([number|array|Sgss_Graphics_Transform $sx = 1], [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])

The constructor

Sgss_Graphics_Transform composite (number|array|Sgss_Graphics_Transform $sx, [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])

Composites this transformation matrix with another

Sgss_Graphics_Transform composition (number|array|Sgss_Graphics_Transform $sx, [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])

Returns the composited transformation matrix with another

static Sgss_Graphics_Transform createReflection ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])

Creates an returns the specified reflection transformation matrix

static Sgss_Graphics_Transform createRotation (number $theta, [number $x = 0], [number $y = 0])

Creates an returns the specified rotation transformation matrix

static Sgss_Graphics_Transform createScale (number $sx, number $sy)

Creates an returns the specified scaling transformation matrix

static Sgss_Graphics_Transform createShear (number $rx, number $ry)

Creates an returns the specified shearing transformation matrix

static Sgss_Graphics_Transform createTranslation (number $tx, number $ty)

Creates an returns the specified translation transformation matrix

number determinant ()

Returns the determinant of this matrix

boolean drawImagick (Imagick|ImagickDraw $imagick, [number $x = 0], [number $y = 0])

Applies this transformation matrix to the specified ImagickDraw instance

array getImagick ()

Converts this transformation matrix to an array used with Imagick

number getScaleX ()

Returns the scaling x element

number getScaleY ()

Returns the scaling y element

number getShearX ()

Returns the shearing x element

number getShearY ()

Returns the shearing y element

Sgss_Graphics_Transform getTransform ()

Returns another object representing this transformation matrix

number getTranslateX ()

Returns the translation x element

number getTranslateY ()

Returns the translation y element

Sgss_Graphics_Transform inverse ()

Returns the inversed transformation matrix

boolean offsetExists (mixed $offset)
mixed offsetGet (mixed $offset)
mixed offsetSet (mixed $offset, mixed $value)
void offsetUnset (mixed $offset)
Sgss_Graphics_Transform reflect ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])

Reflects this transformation matrix

Sgss_Graphics_Transform rotate (number $theta, [number $x = 0], [number $y = 0])

Rotates this transformation matrix

Sgss_Graphics_Transform scale (number $sx, number $sy)

Scales this transformation

void setScaleX (number $sx)

Sets the scaling x element to the specified value

void setScaleY (number $sy)

Sets the scaling y element to the specified value

void setShearX (number $rx)

Sets the shearing x element to the specified value

void setShearY (number $ry)

Sets the shearing y element to the specified value

void setTransform (Sgss_Graphics_Transform $t)

Sets this transformation matrix to the specified value

void setTranslateX (number $tx)

Sets the translation x element to the specified value

void setTranslateY (number $ty)

Sets the translation y element to the specified value

Sgss_Graphics_Transform shear (number $rx, number $ry)

Shears this transformation matrix

array toArray ()

Converts this transformation matrix to an array

Sgss_Graphics_Transform toReflection ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])

Sets this transformation matrix to the specified reflection transformation

Sgss_Graphics_Transform toRotation (number $theta, [number $x = 0], [number $y = 0])

Sets this transformation matrix to the specified rotation transformation

Sgss_Graphics_Transform toScale (number $sx, number $sy)

Sets this transformation matrix to the specified scaling transformation

Sgss_Graphics_Transform toShear (number $rx, number $ry)

Sets this transformation matrix to the specified shearing transformation

Sgss_Graphics_Transform toTranslation (number $tx, number $ty)

Sets this transformation matrix to the specified translation transformation

array transform (number $x, number $y)

Transform the specified vector with this transformation matrix

Sgss_Graphics_Transform translate (number $tx, number $ty)

Translates this transformation matrix

mixed __get (mixed $name)
mixed __set (mixed $name, mixed $value)
string __toString ()

Variable detail

$_rx 

Shearing x element

Signature:
protected number $_rx


$_ry 

Shearing y element

Signature:
protected number $_ry


$_sx 

Scaling x element

Signature:
protected number $_sx


$_sy 

Scaling y element

Signature:
protected number $_sy


$_tx 

Translation x element

Signature:
protected number $_tx


$_ty 

Translation y element

Signature:
protected number $_ty


Method detail

__construct

The constructor

Parameters:
  • number|array|Sgss_Graphics_Transform $sx

    Scaling x element or a transformation matrix

  • number $rx

    Shearing x element

  • number $tx

    Translation x element

  • number $ry

    Shearing y element

  • number $sy

    Scaling y element

  • number $ty

    Translation y element

Signature:
public __construct ([number|array|Sgss_Graphics_Transform $sx = 1], [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])


composite

Composites this transformation matrix with another

The resulting transformation matrix A' is equivalent to the following:

     A' = A x T

where A denotes this transformation matrix and T denotes another.

Parameters:
  • number|array|Sgss_Graphics_Transform $sx

    Scaling x element or a transformation matrix to be applied to this transformation matrix

  • number $rx

    Shearing x element to be applied to this transformation matrix

  • number $tx

    Translation x element to be applied to this transformation matrix

  • number $ry

    Shearing y element to be applied to this transformation matrix

  • number $sy

    Scaling y element to be applied to this transformation matrix

  • number $ty

    Translation y element to be applied to this transformation matrix

Returns:
Sgss_Graphics_Transform -- This object for convenience
Signature:
public Sgss_Graphics_Transform composite (number|array|Sgss_Graphics_Transform $sx, [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])


composition

Returns the composited transformation matrix with another

This is the same as composition() except the returned value is a new object.

Parameters:
  • number|array|Sgss_Graphics_Transform $sx

    Scaling x element or transformation matrix to be applied to this transformation matrix

  • number $rx

    Shearing x element to be applied to this transformation matrix

  • number $tx

    Translation x element to be applied to this transformation matrix

  • number $ry

    Shearing y element to be applied to this transformation matrix

  • number $sy

    Scaling y element to be applied to this transformation matrix

  • number $ty

    Translation y element to be applied to this transformation matrix

Returns:
Sgss_Graphics_Transform -- Composited transformation
Signature:
public Sgss_Graphics_Transform composition (number|array|Sgss_Graphics_Transform $sx, [number $rx = 0], [number $tx = 0], [number $ry = 0], [number $sy = 1], [number $ty = 0])


createReflection 

Creates an returns the specified reflection transformation matrix

The resulting transformation matrix A is equivalent to the following:

         [ hori   0    x (1 - hori) ]
     A = [  0    vert  y (1 - vert) ]
         [  0     0          1      ]

where hori and vert denote -1 or 1 depending on whether the $vert and $hori are true or false.

Parameters:
  • boolean $vert

    Wheter to reflect the resulting transformation matrix

  • boolean $hori

    Wheter to reflect the resulting transformation matrix

  • number $x

    Location of x axis along which the resulting transformation matrix to be refrected

  • number $y

    Location of y axis along which the resulting transformation matrix to be refrected

Returns:
Sgss_Graphics_Transform -- Reflection transformation
Uses:
Sgss_Graphics_Transform::toReflection()
Signature:
public static Sgss_Graphics_Transform createReflection ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])


createRotation 

Creates an returns the specified rotation transformation matrix

The resulting transformation matrix A is equivalent to the following:

          [ cos(r)  -sin(r)  x - x cos(r) + y sin(r) ]
     A' = [ sin(r)   cos(r)  x - y cos(r) - x sin(r) ]
          [   0        0                1            ]

where sin(r) and cos(r) denote the sine and cosine values of the $theta parameter.

Parameters:
  • number $theta

    Rotation angle of the resulting transformation matrix in degree

  • number $x

    X coordinate of the rotation center

  • number $y

    Y coordinate of the rotation center

Returns:
Sgss_Graphics_Transform -- Rotation transformation
Uses:
Sgss_Graphics_Transform::toRotation()
Signature:
public static Sgss_Graphics_Transform createRotation (number $theta, [number $x = 0], [number $y = 0])


createScale 

Creates an returns the specified scaling transformation matrix

The resulting transformation matrix A is equivalent to the following:

          [ sx  0   0 ]
     A' = [ 0   sy  0 ]
          [ 0   0   1 ]

Parameters:
  • number $sx

    Scaling x element of the resulting transformation matrix

  • number $sy

    Scaling y element of the resulting transformation matrix

Returns:
Sgss_Graphics_Transform -- Scaling transformation
Uses:
Sgss_Graphics_Transform::toScale()
Signature:
public static Sgss_Graphics_Transform createScale (number $sx, number $sy)


createShear 

Creates an returns the specified shearing transformation matrix

The resulting transformation matrix A is equivalent to the following:

         [ 1   rx  0 ]
     A = [ ry  1   0 ]
         [ 0   0   1 ]

Parameters:
  • number $rx

    Shearing x element of the resulting transformation matrix

  • number $ry

    Shearing y element of the resulting transformation matrix

Returns:
Sgss_Graphics_Transform -- Shearing transformation
Uses:
Sgss_Graphics_Transform::toShear()
Signature:
public static Sgss_Graphics_Transform createShear (number $rx, number $ry)


createTranslation 

Creates an returns the specified translation transformation matrix

The resulting transformation matrix A is equivalent to the following:

         [ 1   0   tx ]
     A = [ 0   1   ty ]
         [ 0   0   1  ]

Parameters:
  • number $tx

    Translation x element of the resulting transformation matrix

  • number $ty

    Translation y element of the resulting transformation matrix

Uses:
Sgss_Graphics_Transform::toTranslation() - Translation transformation
Signature:
public static Sgss_Graphics_Transform createTranslation (number $tx, number $ty)


determinant

Returns the determinant of this matrix

The determinant is caluculated by the following formula:

              | sx  rx  tx |
     det(A) = | ry  sy  ty | = sx sy - rx ry
              | 0   0   1  |

where A denotes this transformation matrix.

Returns:
number -- Determinant of this matrix
Used by:
Sgss_Graphics_Transform::inverse()
Signature:
public number determinant ()


drawImagick

Applies this transformation matrix to the specified ImagickDraw instance

Parameters:
  • Imagick|ImagickDraw $imagick

    ImagickDraw instance

  • number $x

    Offset x (ignored)

  • number $y

    Offset y (ignored)

Returns:
boolean -- True when this operation succeeded
Specified by:
Related subject:
Sgss_Graphics_Imagick_Draw_Interface::drawImagick()
Signature:
public boolean drawImagick (Imagick|ImagickDraw $imagick, [number $x = 0], [number $y = 0])


getImagick

Converts this transformation matrix to an array used with Imagick

Returned array takes the following form:

  1.  array('sx' => $sx'ry' => $rx'tx' => $tx,
  2.        'rx' => $ry'sy' => $sy'ty' => $ty)

Note that it seems not equivalent to the common naming of affine transformation matrix (rx and ry), but Imagick recognizes rx to be ry and vice versa. Probably because the y axis of the image is reversed to its apparance.

Returns:
array -- Array representing this transformation matrix to be used with Imagick
Specified by:
Related subject:
Sgss_Graphics_Imagick_Get_Interface::getImagick()
Signature:
public array getImagick ()


getScaleX

Returns the scaling x element

Returns:
number -- Scaling x element
Signature:
public number getScaleX ()


getScaleY

Returns the scaling y element

Returns:
number -- Scaling y element
Signature:
public number getScaleY ()


getShearX

Returns the shearing x element

Returns:
number -- Shearing x element
Signature:
public number getShearX ()


getShearY

Returns the shearing y element

Returns:
number -- Shearing y element
Signature:
public number getShearY ()


getTransform

Returns another object representing this transformation matrix

Returns:
Sgss_Graphics_Transform -- Another object representing this transformation matrix
Signature:
public Sgss_Graphics_Transform getTransform ()


getTranslateX

Returns the translation x element

Returns:
number -- Translation x element
Signature:
public number getTranslateX ()


getTranslateY

Returns the translation y element

Returns:
number -- Translation y element
Signature:
public number getTranslateY ()


inverse

Returns the inversed transformation matrix

The resulting transformation matrix A' is equivalent to the following:

          [  sy / det(A)  -rx / det(A)   (rx ty - sy tx) / det(A) ]
     A' = [ -ry / det(A)   sx / det(A)   (ry tx - sx ty) / det(A) ]
          [       0            0                    1            ]

where A denotes this transformation matrix, and:

     det(A) = sx sy - rx ry != 0

The A and A' are in the following relation:

     A' x A = A x A' = I(3)

where I(3) denotes the 3x3 identity matrix.

Returns:
Sgss_Graphics_Transform -- Inversed transformation matrix
Throws:
  • Sgss_Graphics_Transform_Exception

    When the determinant is 0

Uses:
Sgss_Graphics_Transform::determinant()
Signature:
public Sgss_Graphics_Transform inverse ()


offsetExists

Parameters:
  • mixed $offset
Specified by:
  • ArrayAccess::offsetExists
Related subject:
ArrayAccess::offsetExists()
Signature:
public boolean offsetExists (mixed $offset)


offsetGet

Parameters:
  • mixed $offset
Specified by:
  • ArrayAccess::offsetGet
Related subject:
ArrayAccess::offsetGet()
Signature:
public mixed offsetGet (mixed $offset)


offsetSet

Parameters:
  • mixed $offset
  • mixed $value
Specified by:
  • ArrayAccess::offsetSet
Related subject:
ArrayAccess::offsetSet()
Signature:
public mixed offsetSet (mixed $offset, mixed $value)


offsetUnset

Parameters:
  • mixed $offset
Specified by:
  • ArrayAccess::offsetUnset
Related subject:
ArrayAccess::offsetUnset()
Signature:
public void offsetUnset (mixed $offset)


reflect

Reflects this transformation matrix

The resulting transformation matrix A' is equivalent to the following:

              [ hori   0    x (1 - hori) ]
     A' = A x [  0    vert  y (1 - vert) ]
              [  0     0          1      ]

where A denotes this transformation matrix, and hori and vert denote -1 or 1 depending on whether the $vert and $hori are true or false.

Parameters:
  • boolean $vert

    Wheter to reflect this transformation matrix

  • boolean $hori

    Wheter to reflect this transformation matrix

  • number $x

    Location of x axis along which this transformation matrix to be refrected

  • number $y

    Location of y axis along which this transformation matrix to be refrected

Returns:
Sgss_Graphics_Transform -- This object for convenience
Uses:
Sgss_Graphics_Transform::translate()
Signature:
public Sgss_Graphics_Transform reflect ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])


rotate

Rotates this transformation matrix

The resulting transformation matrix A' is equivalent to the following:

              [ cos(r)  -sin(r)  x - x cos(r) + y sin(r) ]
     A' = A x [ sin(r)   cos(r)  x - y cos(r) - x sin(r) ]
              [   0        0                1            ]

where A denotes this transformation matrix, and sin(r) and cos(r) denote the sine and cosine values of the $theta parameter.

Parameters:
  • number $theta

    Rotation angle to be applied to this transformation matrix in degree

  • number $x

    X coordinate of the rotation center

  • number $y

    Y coordinate of the rotation center

Returns:
Sgss_Graphics_Transform -- This object for convenience
Uses:
Sgss_Graphics_Transform::translate()
Signature:
public Sgss_Graphics_Transform rotate (number $theta, [number $x = 0], [number $y = 0])


scale

Scales this transformation

The resulting transformation matrix A' is equivalent to the following:

              [ sx  0   0 ]
     A' = A x [ 0   sy  0 ]
              [ 0   0   1 ]

where A denotes this transformation matrix.

Parameters:
  • number $sx

    Scaling x element to be applied to this transformation matrix

  • number $sy

    Scaling y element to be applied to this transformation matrix

Returns:
Sgss_Graphics_Transform -- This object for convenience
Signature:
public Sgss_Graphics_Transform scale (number $sx, number $sy)


setScaleX

Sets the scaling x element to the specified value

Parameters:
  • number $sx

    Scaling x element to set

Signature:
public void setScaleX (number $sx)


setScaleY

Sets the scaling y element to the specified value

Parameters:
  • number $sy

    Scaling y element to set

Signature:
public void setScaleY (number $sy)


setShearX

Sets the shearing x element to the specified value

Parameters:
  • number $rx

    Shearing x element to set

Signature:
public void setShearX (number $rx)


setShearY

Sets the shearing y element to the specified value

Parameters:
  • number $ry

    Shearing y element to set

Signature:
public void setShearY (number $ry)


setTransform

Sets this transformation matrix to the specified value

Parameters:
Signature:
public void setTransform (Sgss_Graphics_Transform $t)


setTranslateX

Sets the translation x element to the specified value

Parameters:
  • number $tx

    Translation x element to set

Signature:
public void setTranslateX (number $tx)


setTranslateY

Sets the translation y element to the specified value

Parameters:
  • number $ty

    Translation y element to set

Signature:
public void setTranslateY (number $ty)


shear

Shears this transformation matrix

The resulting transformation matrix A' is equivalent to the following:

              [ 1   rx  0 ]
     A' = A x [ ry  1   0 ]
              [ 0   0   1 ]

where A denotes this transformation matrix.

Parameters:
  • number $rx

    Shearing x element to be applied to this transformation matrix

  • number $ry

    Shearing y element to be applied to this transformation matrix

Returns:
Sgss_Graphics_Transform -- This object for convenience
Signature:
public Sgss_Graphics_Transform shear (number $rx, number $ry)


toArray

Converts this transformation matrix to an array

Returned array takes the following form:

  1.  array($sx$rx$tx,
  2.        $ry$sy$ty)

Returns:
array -- Array representing this transformation matrix
Signature:
public array toArray ()


toReflection

Sets this transformation matrix to the specified reflection transformation

The resulting transformation matrix A is equivalent to the following:

         [ hori   0    x (1 - hori) ]
     A = [  0    vert  y (1 - vert) ]
         [  0     0          1      ]

where hori and vert denote -1 or 1 depending on whether the $vert and $hori are true or false.

Parameters:
  • boolean $vert

    Wheter to reflect the resulting transformation matrix

  • boolean $hori

    Wheter to reflect the resulting transformation matrix

  • number $x

    Location of x axis along which the resulting transformation matrix to be refrected

  • number $y

    Location of y axis along which the resulting transformation matrix to be refrected

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::createReflection()
Signature:
public Sgss_Graphics_Transform toReflection ([boolean $vert = false], [boolean $hori = false], [number $x = 0], [number $y = 0])


toRotation

Sets this transformation matrix to the specified rotation transformation

The resulting transformation matrix A is equivalent to the following:

          [ cos(r)  -sin(r)  x - x cos(r) + y sin(r) ]
     A' = [ sin(r)   cos(r)  x - y cos(r) - x sin(r) ]
          [   0        0                1            ]

where sin(r) and cos(r) denote the sine and cosine values of the $theta parameter.

Parameters:
  • number $theta

    Rotation angle to set in degree

  • number $x

    X coordinate of the rotation center

  • number $y

    Y coordinate of the rotation center

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::createRotation()
Signature:
public Sgss_Graphics_Transform toRotation (number $theta, [number $x = 0], [number $y = 0])


toScale

Sets this transformation matrix to the specified scaling transformation

The resulting transformation matrix A is equivalent to the following:

          [ sx  0   0 ]
     A' = [ 0   sy  0 ]
          [ 0   0   1 ]

Parameters:
  • number $sx

    Scaling x element to set

  • number $sy

    Scaling y element to set

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::createScale()
Signature:
public Sgss_Graphics_Transform toScale (number $sx, number $sy)


toShear

Sets this transformation matrix to the specified shearing transformation

The resulting transformation matrix A is equivalent to the following:

         [ 1   rx  0 ]
     A = [ ry  1   0 ]
         [ 0   0   1 ]

Parameters:
  • number $rx

    Shearing x element to set

  • number $ry

    Shearing y element to set

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::createShear()
Signature:
public Sgss_Graphics_Transform toShear (number $rx, number $ry)


toTranslation

Sets this transformation matrix to the specified translation transformation

The resulting transformation matrix A is equivalent to the following:

         [ 1   0   tx ]
     A = [ 0   1   ty ]
         [ 0   0   1  ]

Parameters:
  • number $tx

    Translation x element to set

  • number $ty

    Translation y element to set

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::createTranslation() - Translation transformation
Signature:
public Sgss_Graphics_Transform toTranslation (number $tx, number $ty)


transform

Transform the specified vector with this transformation matrix

The resulting vector (x', y') is equivalent to the following:

     [ x']   [ x ]
     [ y'] = [ y ] x A
     [ 1 ]   [ 1 ]

where A denotes this transformation matrix.

Parameters:
  • number $x

    X coodinate of the vector to be transformed

  • number $y

    Y coodinate of the vector to be transformed

Returns:
array -- Tranformed vector array
Signature:
public array transform (number $x, number $y)


translate

Translates this transformation matrix

The resulting transformation matrix A' is equivalent to the following:

              [ 1   0   tx ]
     A' = A x [ 0   1   ty ]
              [ 0   0   1  ]

where A denotes this transformation matrix.

Parameters:
  • number $tx

    Translation x element to be applied to this transformation matrix

  • number $ty

    Translation y element to be applied to this transformation matrix

Returns:
Sgss_Graphics_Transform -- This object for convenience
Used by:
Sgss_Graphics_Transform::reflect(), Sgss_Graphics_Transform::rotate()
Signature:
public Sgss_Graphics_Transform translate (number $tx, number $ty)


__get

Parameters:
  • mixed $name
Signature:
public mixed __get (mixed $name)


__set

Parameters:
  • mixed $name
  • mixed $value
Signature:
public mixed __set (mixed $name, mixed $value)


__toString

Signature:
public string __toString ()