// create an AffineTransform // and a triangle centered on (0,0) and pointing downward // somewhere outside Swing's paint loop AffineTransform tx = new AffineTransform(); Line2D.Double line = new Line2D.Double(0,0,100,100); Polygon arrowHead = new Polygon(); arrowHead.addPoint( 0,5); arrowHead.addPoint( -5, -5); arrowHead.addPoint( 5,-5); // [...] private void drawArrowHead(Graphics2D g2d) { tx.setToIdentity(); double angle = Math.atan2(line.y2-line.y1, line.x2-line.x1); tx.translate(line.x2, line.y2); tx.rotate((angle-Math.PI/2d)); Graphics2D g = (Graphics2D) g2d.create(); g.setTransform(tx); g.fill(arrowHead); g.dispose(); }
public void drawDefaultSequenceFlowIndicator(Line2D.Double line) { double length = DEFAULT_INDICATOR_WIDTH; double halfOfLength = length / 2; double f = 8; Line2D.Double defaultIndicator = new Line2D.Double(-halfOfLength, 0, halfOfLength, 0); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); double dx = f * Math.cos(angle); double dy = f * Math.sin(angle); double x1 = line.x1 + dx; double y1 = line.y1 + dy; AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); transformation.translate(x1, y1); transformation.rotate((angle - 3 * Math.PI / 4)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(defaultIndicator); g.setTransform(originalTransformation); }
transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1);
transformation.setToIdentity(); transformation.rotate(270 * Math.PI / 180);
public void drawConditionalSequenceFlowIndicator(Line2D.Double line) { int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
@Override public void reset() { this.affineTransform.setToIdentity(); }
/** Checks for {@linkplain #checkPermission permission} before setting this transform. */ @Override public void setToIdentity() { checkPermission(); super.setToIdentity(); }
transform.setToIdentity();
@Override public boolean fit(PointMatch[] min_matches) { PointMatch m1 = min_matches[0]; float[] m1_p1 = m1.getP1().getL(); float[] m1_p2 = m1.getP2().getL(); float tx = m1_p1[0] - m1_p2[0]; float ty = m1_p1[1] - m1_p2[1]; affine.setToIdentity(); affine.translate(tx, ty); return true; }
@Override public boolean fit(PointMatch[] min_matches) { PointMatch m1 = min_matches[0]; float[] m1_p1 = m1.getP1().getL(); float[] m1_p2 = m1.getP2().getL(); float tx = m1_p1[0] - m1_p2[0]; float ty = m1_p1[1] - m1_p2[1]; affine.setToIdentity(); affine.translate(tx, ty); return true; }
public void minimize(Collection<PointMatch> matches) { // center of mass: float xo1 = 0, yo1 = 0; float xo2 = 0, yo2 = 0; int length = matches.size(); for (PointMatch m : matches) { float[] m_p1 = m.getP1().getL(); float[] m_p2 = m.getP2().getW(); xo1 += m_p1[0]; yo1 += m_p1[1]; xo2 += m_p2[0]; yo2 += m_p2[1]; } xo1 /= length; yo1 /= length; xo2 /= length; yo2 /= length; float dx = xo1 - xo2; // reversed, because the second will be moved relative to the first float dy = yo1 - yo2; affine.setToIdentity(); affine.translate(-dx, -dy); }
public void minimize(Collection<PointMatch> matches) { // center of mass: float xo1 = 0, yo1 = 0; float xo2 = 0, yo2 = 0; int length = matches.size(); for (PointMatch m : matches) { float[] m_p1 = m.getP1().getL(); float[] m_p2 = m.getP2().getW(); xo1 += m_p1[0]; yo1 += m_p1[1]; xo2 += m_p2[0]; yo2 += m_p2[1]; } xo1 /= length; yo1 /= length; xo2 /= length; yo2 /= length; float dx = xo1 - xo2; // reversed, because the second will be moved relative to the first float dy = yo1 - yo2; affine.setToIdentity(); affine.translate(-dx, -dy); }
g2d.drawPolygon(p1); g2d.drawPolygon(p2); at.setToIdentity(); at.translate(w / 2, h / 2); at.scale(scale, scale);
affine.setToIdentity(); affine.rotate(-angle, xo2, yo2); affine.translate(-dx, -dy);
affine.setToIdentity(); affine.rotate(-angle, xo2, yo2); affine.translate(-dx, -dy);
while (Math.abs(currOffset) <= labelOffset * 2 && !painted) { tx.setToIdentity(); Rectangle2D labelEnvelope; double maxAngleChange = 0;
private static AffineTransform createRotation(Point2D point, Point2D startOfLine, Point2D endOfLine) { AffineTransform tx = new AffineTransform(); Line2D.Double line = new Line2D.Double(startOfLine, endOfLine); tx.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); tx.translate(point.getX(), point.getY()); tx.rotate(angle - (Math.PI / 2)); return tx; }
while (Math.abs(currOffset) <= (labelOffset * 2) && !painted) { tx.setToIdentity(); double maxAngleChange = 0; boolean curved = false;
public void setToIdentity() { inverse = null; transform.setToIdentity(); fireStateChanged(); } }
/** * setter for the scale fires a PropertyChangeEvent with the AffineTransforms representing the * previous and new values for scale and offset * * @param scalex the amount to scale in the x direction * @param scaley the amount to scale in the y direction * @param from the point to transform */ public void setScale(double scalex, double scaley, Point2D from) { transform.setToIdentity(); scale(scalex, scaley, from); }