Java Utililty Methods Polygon Rotate

List of utility methods to do Polygon Rotate

Description

The list of methods to do Polygon Rotate are organized into topic(s).

Method

voidrotate(Polygon poly, double theta)
rotate
double sin = Math.sin(theta);
double cos = Math.cos(theta);
for (int i = 0; i < poly.npoints; i++) {
    double x = poly.xpoints[i];
    double y = poly.ypoints[i];
    poly.xpoints[i] = (int) (x * cos - y * sin);
    poly.ypoints[i] = (int) (x * sin + y * cos);
voidrotateCW(Polygon polygon, int height)
rotate CW
for (int i = 0; i < polygon.npoints; i++) {
    int tmp = polygon.ypoints[i];
    polygon.ypoints[i] = polygon.xpoints[i];
    polygon.xpoints[i] = height - 1 - tmp;
voidrotatePolygon(Polygon pg, double rotAngle, Point centroid, Polygon original)
Rotates a polygon by an angle alpha.
double x, y;
for (int i = 0; i < pg.npoints; i++) {
    if (original != null) {
        x = original.xpoints[i] - centroid.x;
        y = original.ypoints[i] - centroid.y;
    } else {
        x = pg.xpoints[i] - centroid.x;
        y = pg.ypoints[i] - centroid.y;
...
voidrotatePolygon(Polygon poly, double degree)
Rotates a polygon.
int[] nx = new int[poly.npoints];
int[] ny = new int[poly.npoints];
for (int i = 0; i < poly.npoints; i++) {
    nx[i] = (int) Math.round(
            ((double) poly.xpoints[i]) * Math.cos(degree) + ((double) poly.ypoints[i]) * Math.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;