How to Apply transformation to Polygon object in Java

こ雲淡風輕ζ 提交于 2019-12-02 08:41:00

If AffineTransform#createTransformedShape doesn't provide the desired result for Polygons (as it seems to be the case), you can split the Polygon into Points, transform each Point and combine into a new Polygon. Try:

//Polygon mesh
//AffineTransform at

int[] x = mesh.xpoints;
int[] y = mesh.ypoints;
int[] rx = new int[x.length];
int[] ry = new int[y.length];

for(int i=0; i<mesh.npoints; i++){
  Point2d p = new Point2d.Double(x[i], y[i]);
  at.transform(p,p);
  rx[i]=p.x;
  ry[i]=p.y;
}

mesh = new Polygon(rx, ry, mesh.npoints)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!