Saturday 18 May 2013

31. ROTATION (2-D TRANSFORMATION)


Code:
import java.math.*;
import java.util.*;
import java.awt.*;
import java.applet.*;
public class Rotation extends Applet
{
public void paint(Graphics g)
{
int i,j,k;
double r=30*3.14/180;
int x1,y1,x2,y2,x3,y3,x11,y11,x22,y22,x33,y33;
x1=150;
y1=200;
x2=250;
y2=250;
x3=230;
y3=270;
g.drawLine(x1,y1,x2,y2);
g.drawLine(x2,y2,x3,y3);
g.drawLine(x1,y1,x3,y3);
double p1[][]=new double[3][3];
int p[][]=new int[3][3];
double t[][]=new double[3][3];
t[0][0]=t[1][1]=Math.cos(r);
t[0][1]=-(Math.sin(r));
t[1][0]=Math.sin(r);
t[2][2]=1;
t[0][2]=t[1][2]=t[2][0]=t[2][1]=0;
p[0][0]=x1;
p[0][1]=x2;
p[0][2]=x3;
p[1][0]=y1;
p[1][1]=y2;
p[1][2]=y3;
p[2][0]=p[2][1]=p[2][2]=1;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
p1[i][j]=0;
for(k=0;k<3;k++)
{
p1[i][j]=p1[i][j]+t[i][k]*p[k][j];
}
}
System.out.println();
}
x11=(int)p1[0][0];
x22=(int)p1[0][1];
x33=(int)p1[0][2];
y11=(int)p1[1][0];
y22=(int)p1[1][1];
y33=(int)p1[1][2];
g.drawLine(x11,y11,x22,y22);
g.drawLine(x22,y22,x33,y33);
g.drawLine(x11,y11,x33,y33);
}
}
/*<applet code="Rotation.class" width="800" height="800">
 </applet>*/

OUTPUT:



















Need the code??

No comments:

Post a Comment