计算机图形学第三次实验报告
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算机图形学第三次实验报告
Java 姓名所使用的语
言
学号完成日期16/12/3实验任务1
1、已知第55页Bresenham可以绘制1/4圆,请利用旋转变换
绘制完整圆
import .*;
import .*;
import
import .*;
public class Bresenham extends Applet
{ public void paint(Graphics g)
{ Graphics2D g2=(Graphics2D)g;
;
int r=100, x, y, e, x1, y1;
double xx, yy;
x=0; y=r; e=1-r;
while(x { ; if(e<0) {e=e+2*x+3;x++;} else {e=e+2*(x-y)+5;x++;y=y-1;} (x+200,y+200,1,1); xx=*x+*y ; yy=*x+*y; x1=(int)(xx); y1=(int)(yy); (x1+200,y1+200,1,1); x1=y ; y1=-x; (x1+200,y1+200,1,1); x1=-y ; y1=x; (x1+200,y1+200,1,1); xx=**y ; yy=*x+*y; x1=(int)(xx) ; y1=(int)(yy) ; (x1+200,y1+200,1,1); xx=*x+*y ; yy=**y; x1=(int)(xx) ; y1=(int)(yy) ; (x1+200,y1+200,1,1); x1=-x; y1=-y; (x1+200,y1+200,1,1); xx=**y ; yy=**y; x1=(int)(xx) ; y1=(int)(yy) ; (x1+200,y1+200,1,1); } } } 2、已知第57页中点算法可以绘制1/4椭圆,请利用旋转变换绘制完整椭 圆 import .*; import .*; import import .*; public class mid_circle extends Applet { public void paint(Graphics g) { Graphics2D g2=(Graphics2D)g; ; int r=100, x, y, e, x1, y1; double xx, yy; x=0; y=r; e=2*(1-r); while(x { ; if(e<0) {e=e+2*x+3;x++;} Else {e=e+2*(x-y)+5;x++;y=y-1;} (x+200,y+200,1,1); xx=*x+*y ; yy=*x+*y; x1=(int)(xx); y1=(int)(yy); (x1+200,y1+200,1,1); x1=y ; y1=-x; (x1+200,y1+200,1,1); x1=-y ; y1=x; (x1+200,y1+200,1,1); xx=**y ; yy=*x+*y; x1=(int)(xx; y1=(int)(yy) ; (x1+200,y1+200,1,1); xx=*x+*y ; yy=**y; x1=(int)(xx) ; y1=(int)(yy) ; (x1+200,y1+200,1,1); x1=-x; y1=-y; (x1+200,y1+200,1,1); xx=**y ; yy=**y; x1=(int)(xx) ; y1=(int)(yy) ; (x1+200,y1+200,1,1); } } } 实验任务2 : 将一矩形平移x=200,y=200,并将x缩小1/5的程序 import import import import import 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}; (x, y,5); for(int i=0;i<;i++){ x[i]=x[i]+200; y[i]=y[i]+200; ; } for(int i=0;i<;i++){ x[i]=x[i]/5; ; } (x, y,5); } } 实验任务3: 将一矩形完成以下变换矩阵工作 import import import import public class jihebianhuan extends JApplet{ public void paint(Graphics g) { Graphics2D g2=(Graphics2D)g; int x[]={40,100,100,40,40},y[]={80,80,140,140,80}; (x, y,5); for(int i=0;i<;i=i+5){ x[i]=x[i]/2-y[i]+200;x[i+1]=x[i+1]/2-y[i+1]+200; x[i+2]=x[i+2]/2-y[i+2]+200; x[i+3]=x[i+3]/2-y[i+3]+200; x[i+4]=x[i+4]/2-y[i+4]+200; y[i]=x[i]*2/3+y[i]*2+200; y[i+1]=x[i+1]*2/3+y[i+1]*2+200;y[i+2]=x[i+2]*2/3+y[i+2 ]*2+200; y[i+3]=x[i+3]*2/3+y[i+3]*2+200;y[i+4]=x[i+4]*2/3+y[i+4 ]*2+200;; } (x, y,5); } } 实验任务4:给出任意三角形进行几何变换 import import import import public class sanjiaoxing extends JApplet{ public void paint(Graphics g) { Graphics2D g2=(Graphics2D)g; int x[]={15,60,30,15},y[]={30,30,60,30}; (x, y,4); for(int i=0;i<;i=i+4){ x[i]=x[i]*2-y[i]+20; x[i+1]=x[i+1]*2-y[i+1]+20; x[i+2]=x[i+2]*2-y[i+2]+20; x[i+3]=x[i+3]*2-y[i+3]+20; y[i]=x[i]/3+y[i]*2-10;