Students Of FX?? Hang here out..
 
Home­Portal­Calendar­Gallery­FAQ­Search­Memberlist­Usergroups­Register­Log in
Share | 
 

 Ex. No : 4 3D Transformations

View previous topic View next topic Go down 
AuthorMessage
Admin
Admin


Year Of Joining: 06
Posts: 33
Points: 1367
Reputation: 0
Join date: 2009-06-17
Age: 21
Location: Tirunelveli

PostSubject: Ex. No : 4 3D Transformations   Sat Aug 01, 2009 9:39 am

Ex. No : 4 3D Transformations



//<applet code=td18 height=250 width=250></applet>
import java.awt.*;
import java.applet.*;
import java.lang.*;
import javax.swing.JOptionPane;
public class td18 extends Applet
{
int flag,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8,x=0,y=0,sf,xx,yy,zz,n1,n2,xt,yt,zt,xx1,yy1,zz1,n3,shx;
double a,b,c,d,e,r;
public void paint(Graphics e)
{
e.drawString("Before",x1-50,y1);
e.drawRect(x1,y1,xx,yy);
e.drawRect(x3,y3,xx,yy);
e.drawLine(x1,y1,x3,y3);
e.drawLine(x1,y2,x3,y4);
e.drawLine(x2,y1,x4,y3);
e.drawLine(x2,y2,x4,y4);
e.drawString("After",x6+50,y5);
if(n1<5)
{
e.drawRect(x5,y5,xx1,yy1);
e.drawRect(x7,y7,xx1,yy1);
e.drawLine(x5,y5,x7,y7);
e.drawLine(x5,y6,x7,y8);
e.drawLine(x6,y5,x8,y7);
e.drawLine(x6,y6,x8,y8);
}
else
{
e.drawLine(x5+shx,y5,x2+shx,y5);
e.drawLine(x5+shx,y5,x5,y6);
e.drawLine(x5+shx,y5,x7+shx,y7);
e.drawLine(x6,y6,x5,y6);
e.drawLine(x6,y6,x6+shx,y5);
e.drawLine(x6,y6,x8,y8);
e.drawLine(x7+shx,y7,x8+shx,y7);
e.drawLine(x7+shx,y7,x7,y8);
e.drawLine(x8,y8,x8+shx,y7);
e.drawLine(x8,y8,x7,y8);
e.drawLine(x6+shx,y5,x8+shx,y7);
e.drawLine(x5,y6,x7,y8);
}
if(n1==0)
option();
}
public void option()
{
do
{
n1=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice:\n 1.Translation\n2.Reflect\n3.Scale\n4.Rotation\n5.Shearing\n6.Exit"));
switch(n1)
{
case 1:
{
xt=Integer.parseInt(JOptionPane.showInputDialog("Enter the x value of translation"));
yt=Integer.parseInt(JOptionPane.showInputDialog("Enter the y value of translation"));
x5=x1+xt;
x6=x2+xt;
x7=x3+xt;
x8=x4+xt;
y5=y1+yt;
y6=y2+yt;
y7=y3+yt;
y8=y4+yt;
xx1=xx;
yy1=yy;
zz1=zz;
repaint();
option();
break;
}
case 2:
{
n2=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice:\n1.Reflection about x-axis\n2.Reflection about y-axis\n3.Reflection about xy-axis"));
switch(n2)
{
case 1:
{
x5=x1+(3*zz);
x6=x2+(3*zz);
x7=x3+zz;
x8=x4+zz;
y5=y1;
y6=y2;
y7=y3;
y8=y4;
break;
}
case 2:
{
y5=y1+(3*zz);
y6=y2+(3*zz);
y7=y3+zz;
y8=y4+zz;
x5=x1;
x6=x2;
x7=x3;
x8=x4;
break;
}
case 3:
{
x5=x1+(3*zz);
x6=x2+(3*zz);
x7=x3+zz;
x8=x4+zz;
y5=y1+(3*zz);
y6=y2+(3*zz);
y7=y3+zz;
y8=y4+zz;
break;
}}
xx1=xx;
yy1=yy;
zz1=zz;
repaint();
option();
break;
}
case 3:
{
xt=Integer.parseInt(JOptionPane.showInputDialog("Enter the x value of scaling"));
yt=Integer.parseInt(JOptionPane.showInputDialog("Enter the y value of scaling"));
x5=x1*xt;
x6=x2*xt;
x7=x3*xt;
x8=x4*xt;
y5=y1*yt;
y6=y2*yt;
y7=y3*yt;
y8=y4*yt;
xx1=xx*xt;
yy1=yy*yt;
repaint();
option();
break;
}
case 4:
{
r=Integer.parseInt(JOptionPane.showInputDialog("Enter the rotation angle"));
r=r*-1;
r=Math.toRadians(r);
a=Math.cos(r);
b=Math.sin(r);
x7=x3;
y7=y3;
x8=x4;
y8=y4;
x6=x2;
y6=y2;
x5=x1;
y5=y1;
x7=(int)(x1+((x7-x1)*a)-((y7-y1)*b));
y7=(int)(y1+((x7-x1)*b)-((y7-y1)*a));
x8=(int)(x2+((x8-x2)*a)-((y8-y2)*b));
y8=(int)(y2+((x8-x2)*b)-((y8-y2)*a));
repaint();
option();
break;
}
case 5:
{
shx=Integer.parseInt(JOptionPane.showInputDialog("Enter the value of shear"));
x5=x1;
x6=x2;
x7=x3;
x8=x4;
y5=y1;
y6=y2;
y7=y3;
y8=y4;
repaint();
option();
break;
}}}
while(n1<b);
}
public void init()
{
x1=Integer.parseInt(JOptionPane.showInputDialog("Enter the x value of start point"));
y1=Integer.parseInt(JOptionPane.showInputDialog("Enter the y value of start point"));
xx=Integer.parseInt(JOptionPane.showInputDialog("Enter the value of length"));
yy=Integer.parseInt(JOptionPane.showInputDialog("Enter the value of height"));
zz=Integer.parseInt(JOptionPane.showInputDialog("Enter the value of width"));
x2=x1+xx;
y2=y1+yy;
x3=x1+zz;
y3=y1+zz;
x4=x2+zz;
y4=y2+zz;
xx1=xx;
yy1=yy;
zz1=zz;
x5=x1;
x6=x2;
x7=x3;
x8=x4;
y5=y1;
y6=y2;
y7=y3;
y8=y4;
repaint();
}}


Back to top Go down
View user profile http://itcians.subjectdebate.com
 

Ex. No : 4 3D Transformations

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Digital Dreams :: Final IT :: Laboratory Discussions :: Graphics And Multimedia Lab [Cs1355]-