In case this is useful to anyone else, here is the Java code I used to do this.
public static AffineTransform deriveAffineTransform(
double oldX1, double oldY1,
double oldX2, double oldY2,
double oldX3, double oldY3,
double newX1, double newY1,
double newX2, double newY2,
double newX3, double newY3) {
double[][] oldData = { {oldX1, oldX2, oldX3}, {oldY1, oldY2, oldY3}, {1, 1, 1} };
RealMatrix oldMatrix = MatrixUtils.createRealMatrix(oldData);
double[][] newData = { {newX1, newX2, newX3}, {newY1, newY2, newY3} };
RealMatrix newMatrix = MatrixUtils.createRealMatrix(newData);
RealMatrix inverseOld = new LUDecomposition(oldMatrix).getSolver().getInverse();
RealMatrix transformationMatrix = newMatrix.multiply(inverseOld);
double m00 = transformationMatrix.getEntry(0, 0);
double m01 = transformationMatrix.getEntry(0, 1);
double m02 = transformationMatrix.getEntry(0, 2);
double m10 = transformationMatrix.getEntry(1, 0);
double m11 = transformationMatrix.getEntry(1, 1);
double m12 = transformationMatrix.getEntry(1, 2);
return new AffineTransform(m00, m10, m01, m11, m02, m12);
}