Here you can find the source of rotatePolygon(Polygon poly, double degree)
Parameter | Description |
---|---|
poly | a parameter |
degree | a parameter |
public static void rotatePolygon(Polygon poly, double degree)
//package com.java2s; //License from project: Apache License import java.awt.Polygon; public class Main { /**// w w w . j ava 2 s. co m * Rotates a polygon. * @param poly * @param degree */ public static void rotatePolygon(Polygon poly, double degree) { int[] nx = new int[poly.npoints]; int[] ny = new int[poly.npoints]; for (int i = 0; i < poly.npoints; i++) { // x'= x*cos(degree)+y*sin(degree) nx[i] = (int) Math.round( ((double) poly.xpoints[i]) * Math.cos(degree) + ((double) poly.ypoints[i]) * Math.sin(degree)); // y'= x*cos(degree)-y*sin(degree) ny[i] = (int) Math.round( ((double) poly.xpoints[i]) * Math.sin(degree) - ((double) poly.ypoints[i]) * Math.cos(degree)); } poly.xpoints = nx; poly.ypoints = ny; } }