public void paint(Graphics g) { Polygon pt = at.transform(p); g.translate(xtranslate, ytranslate); g.drawPolygon(pt); for (int i = 0; i < pt.npoints; i++) g.drawString("p" + i, pt.xpoints[i], pt.ypoints[i]); Rectangle r = pt.getBounds(); g.drawString("h=" + r.height + " w=" + r.width, r.height / 2, r.width / 2); }
// p0 p1 // p3 p2 private void init() { int x2 = x1 + width; int y2 = y1 + height; p.addPoint(x1, y1); p.addPoint(x2, y1); p.addPoint(x2, y2); p.addPoint(x1, y2); centroid = Mat3.centroid(p); setPose(0, 1, 1); }
public Polygon getPolygon() { return at.transform(p); }
public void apply() { p = at.transform(p); xf.xform(at); }
public void setShear(double theta, double shx, double shy) { Mat3 tr1 = new Mat3(); Mat3 tr2 = new Mat3(); Mat3 rt = new Mat3(); Mat3 sc = new Mat3(); centroid = rt.centroid(p); tr1.setTranslation(centroid[0], centroid[1]); sc.setShear(shx, shy); rt.setRotation(theta); tr2.setTranslation(-centroid[0], -centroid[1]); at = tr1.multiply(rt); at = at.multiply(sc); at = at.multiply(tr2); }