计算机图形学实验 下载本文

内容发布更新时间 : 2024/5/18 5:28:04星期一 下面是文章的全部内容请认真阅读。

if((LEFT&code)!=0) { x=x3;

y=y3+(long)(y2-y3)*(xl-x3)/(x2-x3); }

else if((RIGHT&code)!=0) { x=xr;

y=y1+(long)(y2-y3)*(xr-x3/x2-x3); }

else if((BOTTOM&code)!=0) { y=yb;

x=x1+(long)(x2-x1)*(yb-y3)/(y2-y3); }

else if((TOP&code)!=0) { y=yt;

x=x1+(long)(x2-x1)*(yt-y3)/(y2-y3); }

if(code==code3) {x1=x; y1=y;

encode(x,y,&code3); } else {x2=x; y2=y;

encode(x,y,&code2); } }

setcolor(RED); line(x1,y1,x2,y2); line(x1,y1,x3,y3); line(x2,y2,x3,y3); return; }

void main() {

int graphdriver=DETECT,graphmode;

initgraph(&graphdriver,&graphmode,\ rectangle(xl,yt,xr,yb); line(x1,y1,x2,y2); line(x1,y1,x3,y3); line(x2,y2,x3,y3);

C_S_LINECLIP(x1,y1,x2,y2,x3,y3,xl,xr,yb,yt); getch(); closegraph(); }

实验截图:

实验6 曲线生成算法的实现

实验目的

了解曲线生成的原理,掌握几种常见的曲线生成算法,利用TurboC实现Bezier曲线的生成算法。 实验环境

计算机、Turbo C或其他C语言程序设计环境 实验学时

2学时,必做实验。 实验内容

(1) 了解曲线生成的原理;

(2) 掌握曲线生成算法(Bezier曲线、B样条曲线);

(3) 利用TurboC实现Bezier曲线的生成算法,在屏幕上任意绘制一条三次Bezier曲线。

实验步骤

1、 算法、原理清晰,有详细的设计步骤;

2、 依据算法、步骤或程序流程图,用C语言编写源程序; 3、 编辑源程序并进行调试;

4、 进行运行测试,并结合情况进行调整; 5、 对运行结果进行保存与分析;

6、 打印源程序或把源程序以文件的形式提交; 7、 按格式书写实验报告。

实验代码:

#include \#include \#include \#define MULTIPLE 7 #define ROW 4 struct node{ float x,y; };

void draw_polygon(struct node a[],int originx,int originy) { int n;

for (n=0;n

if (n==0) moveto(originx+a[0].x,originy-a[0].y); lineto(originx+a[n].x,originy-a[n].y); } }

struct node decasteljau(struct node p[],int n,float u) { int i,r;

struct node point,q[20];

for(i=0;i