Created
February 22, 2020 18:26
-
-
Save MinSomai/5224783639ba6ef6e0e9c391e0eed2bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hw; | |
import java.awt.*; | |
import javax.swing.*; | |
import javax.swing.JFrame; | |
public class RotationNegativeAboutOrigin13 extends JFrame{ | |
int xPoly[]= {30,65,86,100,145,95,60}; | |
int yPoly[]= {30,20,36,56,75,105,60}; | |
int i; | |
RotationNegativeAboutOrigin13(){ | |
setTitle("Rotation On Negative"); | |
setSize(1200,1200); | |
setVisible(true); | |
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
} | |
public void paint(Graphics g) { | |
g.translate(400,400); | |
g.drawPolygon(xPoly, yPoly, xPoly.length); | |
rotateAt(-45); | |
} | |
public void rotateAt(double deg) { | |
double angleInRadian=Math.toRadians(deg); | |
for(i=0;i<xPoly.length;i++) { | |
xPoly[i]=(int)Math.round(xPoly[i]*Math.cos(angleInRadian)-yPoly[i]*Math.sin(angleInRadian)); | |
yPoly[i]=(int)Math.round(xPoly[i]*Math.sin(angleInRadian)+yPoly[i]*Math.cos(angleInRadian)); | |
} | |
Graphics g=this.getGraphics(); | |
g.translate(400, 400); | |
g.drawPolygon(xPoly, yPoly, xPoly.length); | |
} | |
public static void main(String[] args) { | |
javax.swing.SwingUtilities.invokeLater(new Runnable() | |
{ | |
public void run() { | |
new RotationNegativeAboutOrigin13(); | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment