计算机图形学直线DDA算法和Bresenham算法.doc_第1页
计算机图形学直线DDA算法和Bresenham算法.doc_第2页
计算机图形学直线DDA算法和Bresenham算法.doc_第3页
计算机图形学直线DDA算法和Bresenham算法.doc_第4页
计算机图形学直线DDA算法和Bresenham算法.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实 验 报 告 课程名称: 计算机图形学 院系名称: 专业班级: 学生姓名: 学 号: 指导教师: 张玉娟 黑龙江工程学院教务处制实验项目直线的生成实验日期2012.3.6实验地点实验楼601同组人数1实验类型 传统实验 现代实验 其 他 验证性 综合性 设计性 其 他 自立式 合作式 研究式 其 他一、实验目的1、熟练掌握DDA、中点直线生成算法、Bresenham直线生成算法;2、能用DDA、中点直线生成算法、Bresenham直线生成算法绘制任意起始点直终止点的直线段。二、实验仪器设备计算机、C#三、实验原理、内容及步骤实验原理:1、数值微分法(DDA)基本思想:从直线段的起点像素出发, 依据直线的微分方程依次确定描述直线的各个像素点。2、中点直线生成算法:3、Bresenham画线算法基本思想:根据直线的斜率确定选择X或者Y方向作为计长方向, 在此方向上每次递增一个单位步长(或者一个像素单位), 另一个方向上是否同时产生一个单位增量由一个计算量很小的判别式来判断。实验内容: 1、分别对DDA、中点直线生成算法、Bresenham直线生成算法生成子程序2、在主事件过程中给出实参,对三个子程序分别调用,完成任意起始点直终止点的直线段的绘制;实验步骤:1、在C#环境下,设计界面,添加4个文本框,三个命令按钮;2、在代码编写窗口,编写DDA、中点直线生成算法、Bresenham直线生成算法子程序,子程序名分别设为DDALine,MidPointLine和BresenhamLine;3、在三个命令按钮单击事件中分别根据文本框中给定的待绘制直线段起始点和终止点坐标调用相应的直线段生成子程序,Form中完成任意起始点直终止点的直线段的绘制;代码与运行结果;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;namespace WindowsFormsApplication_李?熙? public partial class Form1 : Form Bitmap bmp; public Form1() InitializeComponent(); public void midpointline(int x0, int y0, int x1, int y1, Bitmap bmp) int a, b, delta1, delta2, d, x, y; a = y0 - y1; b = x1 - x0; d = 2 * a + b; delta1 = 2 * a; delta2 = 2 * (a + b); x = x0; y = y0; bmp.SetPixel(x, y, Color.Black); while (x x1) if (d 0) x+; y+; d += delta2; else x+; d += delta1; bmp.SetPixel(x, y, Color.Black); 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); public void DDAline(int x0, int y0, int x1, int y1, Bitmap bmp) int k, detalx, detaly, x, y; detalx = x1 - x0; detaly = y1 - y0; k = detaly / detalx; x = x0; y = y0; bmp.SetPixel(x, y, Color.Red); while (x detaly) x+; y = x + k; else y+; x = y + (1 / k); bmp.SetPixel(x, y, Color.Red); private void button1_Click(object sender, EventArgs e) Graphics graphics = this.CreateGraphics(); bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); midpointline(18, 32,256 , 179, bmp); graphics.DrawImage(bmp, new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); private void button2_Click(object sender, EventArgs e) Graphics graphics = this.CreateGraphics(); bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); BresenhamLine(36, 58, 225, 283, bmp); graphics.DrawImage(bmp, new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); private void button3_Click(object sender, EventArgs e) Graphics graphics = this.CreateGraphics(); bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); DDAline(27, 19, 200, 183, bmp); graphics.DrawImage(bmp, new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); 四、实验中存在的问题、解决方法及进一步的想法等主要存在两个问题,第一个问题是对于DDA中点画线法以及bresenham的算法生成还不是特别熟悉,第二个问题就是程序代码的编写问题了,花

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论