• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AffineTransoform will not translate origin

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic