public void scale(float s) { scale(s, s); }
ohio = (PShape)usa.getChild("OH"); PMatrix2D transform = new PMatrix2D(); //apply transforms(position,rotation,scale) to this matrix transform.scale(2); //be aware that the order of operation matters! transform.translate(-800,-300); //this matrix can be used to convert from screen coordinats to SVG coordinates coordSysSvgInv = transform.get(); //clone the svg to screen transformation matrix coordSysSvgInv.invert(); //simply invert it to get the screen to svg coordSysSvgInv.mult(new PVector(x,y),result);//transform PVector by multiplying it to the inverse svg coord. sys. return result;
matrix.scale(1, -1); MarkerSvg marker = new MarkerSvg(id, matrix.get(), size); matrix.translate(size.x, 0); marker.corners[1] = new PVector(matrix.m02, matrix.m12); matrix.translate(0, -size.y); marker.corners[2] = new PVector(matrix.m02, matrix.m12); matrix.translate(-size.x, 0); marker.corners[3] = new PVector(matrix.m02, matrix.m12); marker.cornersSet = true;
return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]); return new PMatrix2D(1, 0, tx, 0, 1, ty); return new PMatrix2D(sx, 0, 0, 0, sy, 0); float s = PApplet.sin(angle); return new PMatrix2D(c, -s, 0, s, c, 0); PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]); mat.rotate(m[0]); mat.translate(-m[1], -m[2]); return mat; return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0); return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0);
protected void pushTransform() { if (transformStack == null) transformStack = new Stack<PMatrix>(); PMatrix mat; if (transform instanceof PMatrix2D) { mat = new PMatrix2D(); } else { mat = new PMatrix3D(); } mat.set(transform); transformStack.push(mat); }
public MarkerSvg(int id, PMatrix2D matrix, PVector size) { this.id = id; this.size = size.get(); this.matrix = matrix.get(); }
public void print() { int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)), PApplet.max(abs(m10), abs(m11), abs(m12)))); int digits = 1; if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop digits = 5; } else { while ((big /= 10) != 0) digits++; // cheap log() } System.out.println(PApplet.nfs(m00, digits, 4) + " " + PApplet.nfs(m01, digits, 4) + " " + PApplet.nfs(m02, digits, 4)); System.out.println(PApplet.nfs(m10, digits, 4) + " " + PApplet.nfs(m11, digits, 4) + " " + PApplet.nfs(m12, digits, 4)); System.out.println(); }
public boolean invert() { float determinant = determinant(); if (Math.abs(determinant) <= Float.MIN_VALUE) { return false; } float t00 = m00; float t01 = m01; float t02 = m02; float t10 = m10; float t11 = m11; float t12 = m12; m00 = t11 / determinant; m10 = -t10 / determinant; m01 = -t01 / determinant; m11 = t00 / determinant; m02 = (t01 * t12 - t11 * t02) / determinant; m12 = (t10 * t02 - t00 * t12) / determinant; return true; }
public void computeCorners() { if (!cornersSet) { PVector c1 = new PVector(0, 0); PVector c2 = new PVector(size.x, 0); PVector c3 = new PVector(size.x, -size.y); PVector c4 = new PVector(0, -size.y); // PVector pos = new PVector(matrix.m02, matrix.m12); // PVector c1 = PVector.add(pos, new PVector(0, 0)); // PVector c2 = PVector.add(pos, new PVector(size.x, 0)); // PVector c3 = PVector.add(pos, new PVector(size.x, size.y)); // PVector c4 = PVector.add(pos, new PVector(0, size.y)); PVector c1T = new PVector(); PVector c2T = new PVector(); PVector c3T = new PVector(); PVector c4T = new PVector(); matrix.mult(c1, c1T); matrix.mult(c2, c2T); matrix.mult(c3, c3T); matrix.mult(c4, c4T); corners[0] = c1T; corners[1] = c2T; corners[2] = c3T; corners[3] = c4T; } }
return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]); float ty = (m.length == 2) ? m[1] : m[0]; return new PMatrix2D(1, 0, tx, 0, 1, ty); float sy = (m.length == 2) ? m[1] : m[0]; return new PMatrix2D(sx, 0, 0, 0, sy, 0); float s = PApplet.sin(angle); return new PMatrix2D(c, -s, 0, s, c, 0); PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]); mat.rotate(m[0]); mat.translate(-m[1], -m[2]); return mat; //.get(null); return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0); return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0);
protected void pushTransform() { if (transformStack == null) transformStack = new Stack<PMatrix>(); PMatrix mat; if (transform instanceof PMatrix2D) { mat = new PMatrix2D(); } else { mat = new PMatrix3D(); } mat.set(transform); transformStack.push(mat); }
public RadialGradient(PShapeSVG parent, XML properties) { super(parent, properties); this.cx = getFloatWithUnit(properties, "cx", svgWidth); this.cy = getFloatWithUnit(properties, "cy", svgHeight); this.r = getFloatWithUnit(properties, "r", svgSizeXY); String transformStr = properties.getString("gradientTransform"); if (transformStr != null) { float t[] = parseTransform(transformStr).get(null); this.transform = new AffineTransform(t[0], t[3], t[1], t[4], t[2], t[5]); Point2D t1 = transform.transform(new Point2D.Float(cx, cy), null); Point2D t2 = transform.transform(new Point2D.Float(cx + r, cy), null); this.cx = (float) t1.getX(); this.cy = (float) t1.getY(); this.r = (float) (t2.getX() - t1.getX()); } } }
public void print() { int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)), PApplet.max(abs(m10), abs(m11), abs(m12)))); int digits = 1; if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop digits = 5; } else { while ((big /= 10) != 0) digits++; // cheap log() } System.out.println(PApplet.nfs(m00, digits, 4) + " " + PApplet.nfs(m01, digits, 4) + " " + PApplet.nfs(m02, digits, 4)); System.out.println(PApplet.nfs(m10, digits, 4) + " " + PApplet.nfs(m11, digits, 4) + " " + PApplet.nfs(m12, digits, 4)); System.out.println(); }
/** * Invert this matrix. Implementation stolen from OpenJDK. * @return true if successful */ public boolean invert() { float determinant = determinant(); if (Math.abs(determinant) <= Float.MIN_VALUE) { return false; } float t00 = m00; float t01 = m01; float t02 = m02; float t10 = m10; float t11 = m11; float t12 = m12; m00 = t11 / determinant; m10 = -t10 / determinant; m01 = -t01 / determinant; m11 = t00 / determinant; m02 = (t01 * t12 - t11 * t02) / determinant; m12 = (t10 * t02 - t00 * t12) / determinant; return true; }