/** Copyright 2004-2008 Ricard Marxer This file is part of Geomerative. Geomerative is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Geomerative is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Geomerative. If not, see . */ package geomerative ; import processing.core.PApplet; /** * RMatrix is a very simple interface for creating, holding 3x3 matrices with the most common 2D affine transformations such as translation, rotation, scaling and shearing. We only have access to the first to rows of the matrix the last row is considered a constant 0, 0, 1 in order to have better performance. * @eexample RMatrix * @usage Geometry * @extended */ public class RMatrix { float m00 = 1F; float m01 = 0F; float m02 = 0F; float m10 = 0F; float m11 = 1F; float m12 = 0F; float m20 = 0F; float m21 = 0F; float m22 = 1F; /** * Create a new matrix given the coefficients. * @eexample RMatrix * @param m00 coefficient 00 of the matrix * @param m01 coefficient 01 of the matrix * @param m02 coefficient 02 of the matrix * @param m10 coefficient 10 of the matrix * @param m11 coefficient 11 of the matrix * @param m12 coefficient 12 of the matrix * @usage Geometry * @related apply ( ) * @related translate ( ) * @related rotate ( ) * @related scale ( ) * @related shear ( ) */ public RMatrix(float m00, float m01, float m02, float m10, float m11, float m12) { set(m00, m01, m02, m10, m11, m12); } /** * Create a new identity matrix. * @eexample RMatrix * @usage Geometry * @related apply ( ) * @related translate ( ) * @related rotate ( ) * @related scale ( ) * @related shear ( ) */ public RMatrix() { m00 = 1F; m01 = 0F; m02 = 0F; m10 = 0F; m11 = 1F; m12 = 0F; } /** * Copy a matrix. * @eexample RMatrix * @param src source matrix from where to copy the matrix * @usage Geometry * @related apply ( ) * @related translate ( ) * @related rotate ( ) * @related scale ( ) * @related shear ( ) */ public RMatrix(RMatrix src) { set(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12); } public RMatrix(String transformationString){ String[] transfTokens = PApplet.splitTokens(transformationString, ")"); // Loop through all transformations for (String transfToken : transfTokens) { // Check the transformation and the parameters String[] transf = PApplet.splitTokens(transfToken, "("); String[] params = PApplet.splitTokens(transf[1], ", "); float[] fparams = new float[params.length]; for(int j=0; j