예제 #1
0
  public void testCompose1() {
    AffineTransformation t0 = AffineTransformation.translationInstance(10, 0);
    t0.rotate(Math.PI / 2);
    t0.translate(0, -10);

    AffineTransformation t1 = AffineTransformation.translationInstance(0, 0);
    t1.rotate(Math.PI / 2);

    checkTransformation(t0, t1);
  }
예제 #2
0
  public void testComposeRotation1() {
    AffineTransformation t0 = AffineTransformation.rotationInstance(1, 10, 10);

    AffineTransformation t1 = AffineTransformation.translationInstance(-10, -10);
    t1.rotate(1);
    t1.translate(10, 10);

    checkTransformation(t0, t1);
  }
  /**
   * Creates an AffineTransformation defined by a pair of control vectors. A control vector consists
   * of a source point and a destination point, which is the image of the source point under the
   * desired transformation. The computed transformation is a combination of one or more of a
   * uniform scale, a rotation, and a translation (i.e. there is no shear component and no
   * reflection)
   *
   * @param src0
   * @param src1
   * @param dest0
   * @param dest1
   * @return the computed transformation
   * @return null if the control vectors do not determine a well-defined transformation
   */
  public static AffineTransformation createFromControlVectors(
      Coordinate src0, Coordinate src1, Coordinate dest0, Coordinate dest1) {
    Coordinate rotPt = new Coordinate(dest1.x - dest0.x, dest1.y - dest0.y);

    double ang = Angle.angleBetweenOriented(src1, src0, rotPt);

    double srcDist = src1.distance(src0);
    double destDist = dest1.distance(dest0);

    if (srcDist == 0.0) return null;

    double scale = destDist / srcDist;

    AffineTransformation trans = AffineTransformation.translationInstance(-src0.x, -src0.y);
    trans.rotate(ang);
    trans.scale(scale, scale);
    trans.translate(dest0.x, dest0.y);
    return trans;
  }
  /**
   * Creates an AffineTransformation defined by a maping between two baselines. The computed
   * transformation consists of:
   *
   * <ul>
   *   <li>a translation from the start point of the source baseline to the start point of the
   *       destination baseline,
   *   <li>a rotation through the angle between the baselines fragment_about the destination start
   *       point,
   *   <li>and a scaling equal to the ratio of the baseline lengths.
   * </ul>
   *
   * If the source baseline has zero length, an identity transformation is returned.
   *
   * @param src0 the start point of the source baseline
   * @param src1 the end point of the source baseline
   * @param dest0 the start point of the destination baseline
   * @param dest1 the end point of the destination baseline
   * @return the computed transformation
   */
  public static AffineTransformation createFromBaseLines(
      Coordinate src0, Coordinate src1, Coordinate dest0, Coordinate dest1) {
    Coordinate rotPt = new Coordinate(src0.x + dest1.x - dest0.x, src0.y + dest1.y - dest0.y);

    double ang = Angle.angleBetweenOriented(src1, src0, rotPt);

    double srcDist = src1.distance(src0);
    double destDist = dest1.distance(dest0);

    // return identity if transformation would be degenerate
    if (srcDist == 0.0) return new AffineTransformation();

    double scale = destDist / srcDist;

    AffineTransformation trans = AffineTransformation.translationInstance(-src0.x, -src0.y);
    trans.rotate(ang);
    trans.scale(scale, scale);
    trans.translate(dest0.x, dest0.y);
    return trans;
  }
 /**
  * Creates an AffineTransformation defined by a single control vector. A control vector consists
  * of a source point and a destination point, which is the image of the source point under the
  * desired transformation. This produces a translation.
  *
  * @param src0 the start point of the control vector
  * @param dest0 the end point of the control vector
  * @return the computed transformation
  */
 public static AffineTransformation createFromControlVectors(Coordinate src0, Coordinate dest0) {
   double dx = dest0.x - src0.x;
   double dy = dest0.y - src0.y;
   return AffineTransformation.translationInstance(dx, dy);
 }
예제 #6
0
 public void testTranslateRotate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(3, 3).rotate(Math.PI / 2);
   checkTransformation(10, 0, t, -3, 13);
   checkTransformation(-10, -10, t, 7, -7);
 }
예제 #7
0
 public void testTranslate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(2, 3);
   checkTransformation(1, 0, t, 3, 3);
   checkTransformation(0, 0, t, 2, 3);
   checkTransformation(-10, -5, t, -8, -2);
 }