1、计算机图形学第三次实验报告姓名所使用的语言Java学号完成日期16/12/3实验任务11、已知第55页Bresenham可以绘制1/4圆,请利用旋转变换绘制完整圆import java.applet.*; import java.awt.*;import java.awt.geom.*; import javax.swing.*;public class Bresenham extends Applet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; g2.setPaint(Color.red); int r=100, x,
2、 y, e, x1, y1; double xx, yy; x=0; y=r; e=1-r; while(xy) g.setColor(Color.RED); if(e0) e=e+2*x+3;x+; else e=e+2*(x-y)+5;x+;y=y-1; g.fillRect(x+200,y+200,1,1); xx=0.7071*x+0.7071*y ; yy=-0.7071*x+0.7071*y; x1=(int)(xx); y1=(int)(yy); g.fillRect(x1+200,y1+200,1,1); x1=y ; y1=-x; g.fillRect(x1+200,y1+2
3、00,1,1); x1=-y ; y1=x; g.fillRect(x1+200,y1+200,1,1); xx=0.7071*x-0.7071*y ; yy=0.7071*x+0.7071*y; x1=(int)(xx) ; y1=(int)(yy) ; g.fillRect(x1+200,y1+200,1,1); xx=-0.707*x+0.707*y ; yy=-0.707*x-0.707*y; x1=(int)(xx) ; y1=(int)(yy) ; g.fillRect(x1+200,y1+200,1,1); x1=-x; y1=-y; g.fillRect(x1+200,y1+2
4、00,1,1); xx=-0.707*x-0.707*y ; yy=0.707*x-0.707*y; x1=(int)(xx) ; y1=(int)(yy) ; g.fillRect(x1+200,y1+200,1,1); 2、已知第57页中点算法可以绘制1/4椭圆,请利用旋转变换绘制完整椭圆import java.applet.*; import java.awt.*;import java.awt.geom.*; import javax.swing.*;public class mid_circle extends Applet public void paint(Graphics g)
5、 Graphics2D g2=(Graphics2D)g; g2.setPaint(Color.red); int r=100, x, y, e, x1, y1;double xx, yy; x=0; y=r; e=2*(1-r); while(xy) g.setColor(Color.RED);if(e0) e=e+2*x+3;x+; Else e=e+2*(x-y)+5;x+;y=y-1; g.fillRect(x+200,y+200,1,1); xx=0.7071*x+0.7071*y ; yy=-0.7071*x+0.7071*y; x1=(int)(xx); y1=(int)(yy)
6、; g.fillRect(x1+200,y1+200,1,1); x1=y ; y1=-x; g.fillRect(x1+200,y1+200,1,1); x1=-y ; y1=x; g.fillRect(x1+200,y1+200,1,1); xx=0.7071*x-0.7071*y ; yy=0.7071*x+0.7071*y; x1=(int)(xx; y1=(int)(yy) ; g.fillRect(x1+200,y1+200,1,1); xx=-0.707*x+0.707*y ; yy=-0.707*x-0.707*y; x1=(int)(xx) ; y1=(int)(yy) ;
7、g.fillRect(x1+200,y1+200,1,1); x1=-x; y1=-y; g.fillRect(x1+200,y1+200,1,1); xx=-0.707*x-0.707*y ; yy=0.707*x-0.707*y; x1=(int)(xx) ; y1=(int)(yy) ; g.fillRect(x1+200,y1+200,1,1); 实验任务2 :将一矩形平移x=200,y=200,并将x缩小1/5的程序import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import j
8、ava.awt.geom.Rectangle2D; import javax.swing.JApplet; public class a extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=20,220,220,20,20,y=100,100,200,200,100; g2.drawPolyline(x, y,5); for(int i=0;ix.length;i+) xi=xi+200; yi=yi+200; g2.setColor(Color.RED); for(int i=0;i
9、x.length;i+) xi=xi/5; g2.setColor(Color.blue); g2.drawPolyline(x, y,5); 实验任务3:将一矩形完成以下变换矩阵工作import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class jihebianhuan extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; in
10、t x=40,100,100,40,40,y=80,80,140,140,80; g2.drawPolyline(x, y,5); for(int i=0;ix.length;i=i+5) xi=xi/2-yi+200;xi+1=xi+1/2-yi+1+200; xi+2=xi+2/2-yi+2+200; xi+3=xi+3/2-yi+3+200; xi+4=xi+4/2-yi+4+200; yi=xi*2/3+yi*2+200; yi+1=xi+1*2/3+yi+1*2+200;yi+2=xi+2*2/3+yi+2*2+200; yi+3=xi+3*2/3+yi+3*2+200;yi+4=x
11、i+4*2/3+yi+4*2+200;g2.setColor(Color.RED); g2.drawPolyline(x, y,5); 实验任务4: 给出任意三角形进行几何变换import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class sanjiaoxing extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=1
12、5,60,30,15,y=30,30,60,30; g2.drawPolyline(x, y,4); for(int i=0;ix.length;i=i+4) xi=xi*2-yi+20; xi+1=xi+1*2-yi+1+20; xi+2=xi+2*2-yi+2+20; xi+3=xi+3*2-yi+3+20; yi=xi/3+yi*2-10; yi+1=xi+1/3+yi+1*2-10; yi+2=xi+2/3+yi+2*2-10; yi+3=xi+3/3+yi+3*2-10; g2.setColor(Color.RED); g2.drawPolyline(x, y,4); 实验任务5:
13、完成下面几何变换为一单位正方形,对由(0,0)和(1,1)两点构成的对角线方向实施比例变换(1,2).import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class zhengfangxing extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=100,200,200,100,100,y=100,100,200,20
14、0,100; g2.drawPolyline(x, y,5); for(int i=0;ix.length;i=i+5) xi=(int)(xi*0.707-yi*0.707)+100; xi+1=(int)(xi+1*0.707-yi+1*0.707)+100; xi+2=(int)(xi+2*0.707-yi+2*0.707)+100; xi+3=(int)(xi+3*0.707-yi+3*0.707)+100; xi+4=(int)(xi+4*0.707-yi+4*0.707)+100; yi=(int)(xi*0.707+yi*0.707)+100; yi+1=(int)(xi+1*0
15、.707+yi+1*0.707)+100; yi+2=(int)(xi+2*0.707+yi+2*0.707)+100; yi+3=(int)(xi+3*0.707+yi+3*0.707)+100; yi+4=(int)(xi+4*0.707+yi+4*0.707)+100; g2.setColor(Color.RED); g2.drawPolyline(x, y,5); 实验任务6: 对于四边形ABCD顶点坐标为A(0,0), B(20,0), C(20,15), D(0,15)1)沿x轴方向缩小一半,y轴增长一倍绘图;import java.awt.Color; import java.a
16、wt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class juxing1extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=100,200,200,100,100,y=100,100,150,150,100; g2.drawPolyline(x, y,5);g2.drawPolyline(x, y,5); 2)将四边形ABCD沿x轴平移100,y轴平移100,然后旋转450绘图;i
17、mport java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class juxing2 extends JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=100,200,200,100,100,y=100,100,150,150,100; g2.drawPolyline(x, y,5); for(int i=0;ix.length;i=i+
18、5) xi=(int)(xi*0.707-yi*0.707)+100; xi+1=(int)(xi+1*0.707-yi+1*0.707)+100; xi+2=(int)(xi+2*0.707-yi+2*0.707)+100; xi+3=(int)(xi+3*0.707-yi+3*0.707)+100; xi+4=(int)(xi+4*0.707-yi+4*0.707)+100; yi=(int)(xi*0.707+yi*0.707)+100; yi+1=(int)(xi+1*0.707+yi+1*0.707)+100; yi+2=(int)(xi+2*0.707+yi+2*0.707)+10
19、0; yi+3=(int)(xi+3*0.707+yi+3*0.707)+100; yi+4=(int)(xi+4*0.707+yi+4*0.707)+100; g2.setColor(Color.blue); g2.drawPolyline(x, y,5); 3) 将四边形ABCD沿y轴平移100,然后将四边形沿y=60作轴对称并绘图。import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JApplet; public class juxing3 exte
20、nds JApplet public void paint(Graphics g) Graphics2D g2=(Graphics2D)g; int x=100,200,200,100,100,y=100,100,150,150,100; g2.drawPolyline(x, y,5); for(int i=0;ix.length;i+) xi=xi+100; g2.setColor(Color.RED); g2.drawPolyline(x, y,5); for(int i=0;ix.length;i+) yi=yi+120; xi=xi; g2.setColor(Color.blue); g2.drawPolyline(x, y,5); 4) 实验任务7: 1)将P137中顶点A(0,0,0),B(20,0,0) ,C(0,10,0) ,D(0,0,10) ,E(20,0,10) ,F(0,10,10);三棱柱ABCDEF绕x轴、y轴、z轴正向旋转,绘出图形。 2)完成P147六面体A(0,2,0),B(2,2,0) ,C(2,0,0) ,D(0,0,0) ,E(0,2,2) , F(2,2,2), G(2,0,2), H(0,0,2)三视图绘制; 3)完成P161例题绘制。 评语