VS中直线的绘制—计算机图形学实验报告一
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
k += 2 * dy
Else
k += 2 * (dy - dx)
y = y + 1
Enห้องสมุดไป่ตู้If
x = x + 1
EndWhile
Else
k = 2 * dx - dy
Whiley < y2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk < 0Then
k += 2 * dx
08地信
学号
200875000203
姓名
指导老师
课程名称
计算机图形学
实验题目
直线的绘制
成绩
一、实验目的:
熟练掌握绘制直线的DDA算法、中点画线算法和Bresenham画线算法。
二、实验准备:
学习绘制直线的DDA算法、中点画线算法和Bresenham画线算法,注意考虑不同斜率条件下算法的变化。
三、实验内容:
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
Dimx1, y1, x2, y2, dx, dy, x, y, k, a, bAsDouble
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Green, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
Else
k += b
EndIf
y += 1
EndWhile
EndIf
EndSub
4.Bresenham画线算法绘制直线
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click'Bresenham画线算法
Dimx1, y1, x2, y2, dx, dy, x, yAsDouble
DimiAsInteger
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Yellow, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
DimpAsPen =NewPen(Color.Red, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
Ifk >= 0Then
k += a
Else
k += a + b
y += 1
EndIf
x += 1
EndWhile
Else
k = 0.5 * a + b
Whiley < y2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk >= 0Then
k += a + b
x += 1
y2 =CDbl(TextBox4.Text)
a = y1 - y2
b = x2 - x1
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
Ifdx > dyThen
k = a + 0.5 * b
Whilex < x2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 = TextBox1.Text
y1 = TextBox2.Text
x2 = TextBox3.Text
y2 = TextBox4.Text
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click'DrawLine()函数画线
Dimx1, y1, x2, y2AsDouble
DimgAsGraphics = PictureBox1.CreateGraphics
y2 =CDbl(TextBox4.Text)
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
Ifdx > dyThen
k = 2 * dy - dx
Whilex < x2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk < 0Then
1程序编写上GDI+中提供的DrawLine ( )函数算法明显比其它三种算法的代码简洁;
2画线效率上GDI+中提供的DrawLine ( )函数直线的绘制明显比其它三种算法高效。
教师意见:
年月日
PictureBox1.Refresh()
EndSub
6.退出程序
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click'退出
End
EndSub
(四)程序运行
(五)在.net环境中利用DDA算法绘制直线、中点画线算法和Bresenham画线算法绘制直线与GDI+中提供的DrawLine ( )函数绘制的直线区别主要表现在:
x += 1
Next
Else
Fori = 0TodyStep1
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
x = x + dx / dy
y += 1
Next
EndIf
EndWhile
EndSub
3.中点画线算法绘制直线
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click'中点画线算法
g.DrawLine(p,CInt(x1),CInt(y1),CInt(x2),CInt(y2))
EndIf
EndSub
2.DDA(数值微分)算法绘制直线
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click'DDA算法画线
y2 =CDbl(TextBox4.Text)
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
While(x < x2)
If(dx >= dy)Then
Fori = 0TodxStep1
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
y = y + dy / dx
在.net环境中利用DDA算法绘制直线、中点画线算法和Bresenham画线算法绘制直线,比较其与GDI+中提供的DrawLine ( )函数绘制的直线有何区别。
四、实验过程及步骤:
(包括程序界面设计、控件属性说明、程序代码和程序运行四部分)
(一)程序界面设计
(二)控件属性说明
例:
(三)程序代码
1.DGI+ DrawLine()函数绘制直线
Else
k += 2 * (dx - dy)
x += 1
EndIf
y += 1
EndWhile
EndIf
EndSub
5.清除线条
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click'清除
whendilutedoillubricationcontactanglecontact西北师范大学学生实验报告学院地环学院专业地理信息系统年级班08学号200875000203姓名指导老师课程名称计算机图形学实验题目直线的绘制成绩一实验目的
西北师范大学学生实验报告
学院
地环学院
专业
地理信息系统
年级、班
Dimx1, y1, x2, y2, dx, dy, x, y, kAsDouble
DimiAsInteger
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Blue, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
Else
k += 2 * (dy - dx)
y = y + 1
Enห้องสมุดไป่ตู้If
x = x + 1
EndWhile
Else
k = 2 * dx - dy
Whiley < y2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk < 0Then
k += 2 * dx
08地信
学号
200875000203
姓名
指导老师
课程名称
计算机图形学
实验题目
直线的绘制
成绩
一、实验目的:
熟练掌握绘制直线的DDA算法、中点画线算法和Bresenham画线算法。
二、实验准备:
学习绘制直线的DDA算法、中点画线算法和Bresenham画线算法,注意考虑不同斜率条件下算法的变化。
三、实验内容:
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
Dimx1, y1, x2, y2, dx, dy, x, y, k, a, bAsDouble
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Green, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
Else
k += b
EndIf
y += 1
EndWhile
EndIf
EndSub
4.Bresenham画线算法绘制直线
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click'Bresenham画线算法
Dimx1, y1, x2, y2, dx, dy, x, yAsDouble
DimiAsInteger
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Yellow, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
DimpAsPen =NewPen(Color.Red, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen
Ifk >= 0Then
k += a
Else
k += a + b
y += 1
EndIf
x += 1
EndWhile
Else
k = 0.5 * a + b
Whiley < y2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk >= 0Then
k += a + b
x += 1
y2 =CDbl(TextBox4.Text)
a = y1 - y2
b = x2 - x1
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
Ifdx > dyThen
k = a + 0.5 * b
Whilex < x2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 = TextBox1.Text
y1 = TextBox2.Text
x2 = TextBox3.Text
y2 = TextBox4.Text
MessageBox.Show("请输入正确的坐标!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
x1 =CDbl(TextBox1.Text)
y1 =CDbl(TextBox2.Text)
x2 =CDbl(TextBox3.Text)
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click'DrawLine()函数画线
Dimx1, y1, x2, y2AsDouble
DimgAsGraphics = PictureBox1.CreateGraphics
y2 =CDbl(TextBox4.Text)
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
Ifdx > dyThen
k = 2 * dy - dx
Whilex < x2
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
Ifk < 0Then
1程序编写上GDI+中提供的DrawLine ( )函数算法明显比其它三种算法的代码简洁;
2画线效率上GDI+中提供的DrawLine ( )函数直线的绘制明显比其它三种算法高效。
教师意见:
年月日
PictureBox1.Refresh()
EndSub
6.退出程序
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click'退出
End
EndSub
(四)程序运行
(五)在.net环境中利用DDA算法绘制直线、中点画线算法和Bresenham画线算法绘制直线与GDI+中提供的DrawLine ( )函数绘制的直线区别主要表现在:
x += 1
Next
Else
Fori = 0TodyStep1
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
x = x + dx / dy
y += 1
Next
EndIf
EndWhile
EndSub
3.中点画线算法绘制直线
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click'中点画线算法
g.DrawLine(p,CInt(x1),CInt(y1),CInt(x2),CInt(y2))
EndIf
EndSub
2.DDA(数值微分)算法绘制直线
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click'DDA算法画线
y2 =CDbl(TextBox4.Text)
dx = x2 - x1
dy = y2 - y1
x = x1
y = y1
EndIf
While(x < x2)
If(dx >= dy)Then
Fori = 0TodxStep1
g.DrawEllipse(p,CInt(x),CInt(y), 1, 1)
y = y + dy / dx
在.net环境中利用DDA算法绘制直线、中点画线算法和Bresenham画线算法绘制直线,比较其与GDI+中提供的DrawLine ( )函数绘制的直线有何区别。
四、实验过程及步骤:
(包括程序界面设计、控件属性说明、程序代码和程序运行四部分)
(一)程序界面设计
(二)控件属性说明
例:
(三)程序代码
1.DGI+ DrawLine()函数绘制直线
Else
k += 2 * (dx - dy)
x += 1
EndIf
y += 1
EndWhile
EndIf
EndSub
5.清除线条
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click'清除
whendilutedoillubricationcontactanglecontact西北师范大学学生实验报告学院地环学院专业地理信息系统年级班08学号200875000203姓名指导老师课程名称计算机图形学实验题目直线的绘制成绩一实验目的
西北师范大学学生实验报告
学院
地环学院
专业
地理信息系统
年级、班
Dimx1, y1, x2, y2, dx, dy, x, y, kAsDouble
DimiAsInteger
DimgAsGraphics = PictureBox1.CreateGraphics
DimpAsPen =NewPen(Color.Blue, 1)
IfTextBox1.Text = ""OrTextBox2.Text = ""OrTextBox3.Text = ""OrTextBox4.Text = ""OrTextBox1.Text = TextBox3.TextOrTextBox2.Text = TextBox4.TextThen