收藏 分销(赏)

直线与圆的绘制.doc

上传人:s4****5z 文档编号:9010071 上传时间:2025-03-11 格式:DOC 页数:7 大小:64.50KB
下载 相关 举报
直线与圆的绘制.doc_第1页
第1页 / 共7页
直线与圆的绘制.doc_第2页
第2页 / 共7页
点击查看更多>>
资源描述
学 号 天津城建大学 计算机图形学实验报告 实验八 直线与圆的绘制 学生姓名 专业、班级 指导教师 成绩 计算机与信息工程学院 2013 年 月 日 天津城建大学 设计性实验任务书 计算机与信息工程 学院 计算机 专业 2 班姓 学号: 课程名称: 计算机图形学 设计题目: 用逐点比较法实现直线和圆的绘制 完成期限:自 2013 年 11月 1 日至 2013 年 11 月 10 日 设计依据、要求及主要内容(可另加附页): 1设计依据: 本课程设计是依据教材<<计算机计算机图形学>>一书的第5章图形算法为设计依据, 制作直线和圆的程序。 2设计要求: 用逐点比较法实现直线和圆的绘制 基本要求: (1) 数据输入项为:直线的起点与终点坐标,圆心坐标与半径 (2) 直线与圆输出在PictureBox控件中 附加要求:(1)通过用户输入可改变直线的线型(实线、虚线与点划线) (3) 通过用户输入可改变直线的线宽(用方刷子处理) 指导教师: 任丽敏 原程序: 逐点画线程序(1) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace zhudianhuaxian { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void BresenhamLine(int x0, int y0, int x1, int y1, Bitmap bmp) { int deltax, deltay, delta1, delta2, d, x, y; deltax = x1 - x0; deltay = y1 - y0; d = 2 * deltay - deltax; delta1 = 2 * deltay; delta2 = 2 * (deltay - deltax); x = x0; y = y0; bmp.SetPixel(x, y, Color.Blue); while (x < x1) { if (d < 0) { x++; d += delta1; } else { x++; y++; d += delta2; } { bmp.SetPixel(x, y, Color.Blue); } } } private void button1_Click(object sender, EventArgs e) { Graphics graphics = this.CreateGraphics(); Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); BresenhamLine(10, 10, 200, 200, bmp); graphics.DrawImage(bmp, new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height)); } } } 运行结果: 逐点画圆程序: #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<graphics.h> void BresenhemCircle(int centerx, int centery, int radius, int color, int type); void initgr(void) /* BGI初始化 */ { int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */ registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */ initgraph(&gd, &gm, ""); setbkcolor(WHITE); } int main(void) { int centerx,centery,radius,color,type; printf("centerx,centery\n"); scanf("%d",&centerx); scanf("%d",&centery); printf("radius\n"); scanf("%d",&radius); printf("color,type\n"); scanf("%d",&color); scanf("%d",&type); initgr(); /*BGI初始化 */ BresenhemCircle(centerx,centery,radius,color,type); getch(); closegraph(); } void BresenhemCircle(int centerx, int centery, int radius, int color, int type) { int x =type= 0; int y = radius; int delta = 2*(1-radius); int direction; while (y >= 0) { if (!type) { putpixel(centerx+x, centery+y, color); putpixel(centerx-x, centery+y, color); putpixel(centerx-x, centery-y, color); putpixel(centerx+x, centery-y, color); } else { line(centerx+x, centery+y, centerx+x, centery-y); line(centerx-x, centery+y, centerx-x, centery-y); } if (delta < 0) { if ((2*(delta+y)-1) < 0) { direction = 1; } else { direction = 2; } } else if(delta > 0) { if ((2*(delta-x)-1) <= 0) { direction = 2; } else { direction = 3; } } else { direction=2; } switch(direction) { case 1: x++; delta += (2*x+1); break; case 2: x++; y--; delta += 2*(x-y+1); break; case 3:y--; delta += (-2*y+1); break; } } } 体会:
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服