• Post Reply Bookmark Topic Watch Topic
  • New Topic

AffineTransoform will not translate origin

 
John Clemens
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using AffineTransform.deltaTransform() to transform some data points. I get expected results for rotations, scaling, and shearing. However, translation seems to be ignored. How is this possible? Why aren't my data points affected by translation transformations?

import java.awt.geom.*;

public class TestXForm {
public static void main(String[] args) {
AffineTransform xform = new AffineTransform();
displayMatrix(xform);
int n = 3;
double pts[] = new double[2*n];
pts[0] = 10.0;
pts[1] = 10.0;
pts[2] = -5.0;
pts[3] = 5.0;
pts[4] = -1.0;
pts[5] = -1.0;
displayPoints(pts, n);
System.out.println("begin transforming data - xform.getType() = " + xform.getType());;
// xform.translate(100.0, -200.0);
// xform.setToTranslation(100.0, -200.0);
// xform = AffineTransform.getTranslateInstance(100.0, -200.0);
xform.rotate(Math.toRadians(90.0), 100.0, -200.0);
// xform.setToRotation(Math.toRadians(90.0), 100.0, -200.0);
// xform.scale(0.5, 2.0);
// xform.shear(2.0, 1.0);
xform.deltaTransform(pts, 0, pts, 0, 3);
System.out.println("end transforming data - xform.getType() = " + xform.getType());
displayMatrix(xform);
displayPoints(pts, n);
}

static public void displayPoints(double pts[], int n) {
for(int i=0; i<n; i++) {
System.out.print("p[" + i + "](" + pts[2*i] + "," + pts[2*i+1] + ")\t\t");
}
System.out.println();
}

static public void displayMatrix(AffineTransform xf) {
int n = 6;
double matrix[] = new double[n];
xf.getMatrix(matrix);
System.out.print("[\t");
for(int i=0; i<n; i+=2) {
System.out.print(matrix + "\t\t");
}
System.out.println("]");
System.out.print("[\t");
for(int i=1; i<n; i+=2) {
System.out.print(matrix + "\t\t");
}
System.out.println("]");
}
}

-------------The output -------------

[ 1.0 0.0 0.0 ]
[ 0.0 1.0 0.0 ]
p[0](10.0,10.0) p[1](-5.0,5.0) p[2](-1.0,-1.0)
begin transforming data - xform.getType() = 0
end transforming data - xform.getType() = 9
[ 0.0 -1.0 -100.0 ]
[ 1.0 -0.0 -300.0 ]
p[0](-10.0,10.0) p[1](-5.0,-5.0) p[2](1.0,-1.0)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!