| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the ezcGraphTransformation class 4 * 5 * @package Graph 6 * @version 1.5 7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. 8 * @license http://ez.no/licenses/new_bsd New BSD License 9 * @access private 10 */ 11 /** 12 * Class defining transformations 13 * 14 * Three dimensional matrices (3x3) may be used to specify transformation of 15 * points, vectors and complexer structures in a two dimensional cartesian 16 * coordinate system. For more details have a look here: 17 * http://en.wikipedia.org/wiki/Transformation_matrix 18 * 19 * There are some classes extending this basic tranformation class, to 20 * give you more convinient access to the creation of such transformation 21 * matrices, which are: 22 * 23 * - ezcGraphRotation (rotations of objects) 24 * - ezcGraphTranslation (moving of objects) 25 * 26 * @version 1.5 27 * @package Graph 28 * @access private 29 */ 30 class ezcGraphTransformation extends ezcGraphMatrix 31 { 32 /** 33 * Constructor 34 * 35 * Creates a matrix with 3x3 dimensions. Optionally accepts an array to 36 * define the initial matrix values. If no array is given an identity 37 * matrix is created. 38 * 39 * @param array $values 40 * @return void 41 */ 42 public function __construct( array $values = null ) 43 { 44 parent::__construct( 3, 3, $values ); 45 } 46 47 /** 48 * Multiplies two matrices 49 * 50 * Multiply current matrix with another matrix and returns the result 51 * matrix. 52 * 53 * @param ezcGraphMatrix $matrix Second factor 54 * @return ezcGraphMatrix Result matrix 55 */ 56 public function multiply( ezcGraphMatrix $matrix ) 57 { 58 $mColumns = $matrix->columns(); 59 60 // We want to ensure, that the matrix stays 3x3 61 if ( ( $this->columns !== $matrix->rows() ) && 62 ( $this->rows !== $mColumns ) ) 63 { 64 throw new ezcGraphMatrixInvalidDimensionsException( $this->columns, $this->rows, $mColumns, $matrix->rows() ); 65 } 66 67 $result = parent::multiply( $matrix ); 68 69 // The matrix dimensions stay the same, so that we can modify $this. 70 for ( $i = 0; $i < $this->rows; ++$i ) 71 { 72 for ( $j = 0; $j < $mColumns; ++$j ) 73 { 74 $this->set( $i, $j, $result->get( $i, $j ) ); 75 } 76 } 77 78 return $this; 79 } 80 81 /** 82 * Transform a coordinate with the current transformation matrix. 83 * 84 * @param ezcGraphCoordinate $coordinate 85 * @return ezcGraphCoordinate 86 */ 87 public function transformCoordinate( ezcGraphCoordinate $coordinate ) 88 { 89 $vector = new ezcGraphMatrix( 3, 1, array( array( $coordinate->x ), array( $coordinate->y ), array( 1 ) ) ); 90 $vector = parent::multiply( $vector ); 91 92 return new ezcGraphCoordinate( $vector->get( 0, 0 ), $vector->get( 1, 0 ) ); 93 } 94 } 95 96 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |