Forums Register Login

AffineTransoform will not translate origin

+Pie Number of slices to send: Send
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)
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 680 times.
Similar Threads
Making a Tetris clone
Quick question about the date class
AffineTransform "transform" method
How to handle rows/columns in arrays
Help me with matrix...please!!!!!!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:47:24.