function toWorld(x,y){ var xx, yy, m, result; m = invMatrix; xx = x - matrix[4]; // remove the translation yy = y - matrix[5]; // by subtracting the origin // return the point {x:?,y:?} by multiplying xx,yy by the inverse matrix return { x: xx * m[0] + yy * m[2], y: xx * m[1] + yy * m[3] } }var matrix = [1,0,0,1,0,0]; var invMatrix = [1,0,0,1]; function createMatrix(x, y, scale, rotate){ var m = matrix; // just to make it easier to type and read var im = invMatrix; // just to make it easier to type and read // create the rotation and scale parts of the matrix m[3] = m[0] = Math.cos(rotate) * scale; m[2] = -(m[1] = Math.sin(rotate) * scale); // add the translation m[4] = x; m[5] = y; // calculate the inverse transformation // first get the cross product of x axis and y axis cross = m[0] * m[3] - m[1] * m[2]; // now get the inverted axis im[0] = m[3] / cross; im[1] = -m[1] / cross; im[2] = -m[2] / cross; im[3] = m[0] / cross; }