计算机图形学直线生成算法

包含DDA算法,中点Bresenham算法,改进的Bresenham算法的完整c语言程序代码,谢谢大家拉~~~... 包含DDA算法,中点Bresenham算法,改进的Bresenham算法的完整c语言程序代码,谢谢大家拉~~~ 展开
祈光怀冷菱
2020-07-03 · TA获得超过3776个赞
知道大有可为答主
回答量:3140
采纳率:28%
帮助的人:228万
展开全部
我连画圆的一块给你吧
需要橡皮筋
椭圆
树什么的可以和我说
我是用
c#写的
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
line
{
public
partial
class
Form1
:
Form
{
Graphics
g;
public
Form1()
{
InitializeComponent();
g
=
pictureBox1.CreateGraphics();
}
private
void
button1_Click_1(object
sender,
EventArgs
e)
{
//
g.TranslateTransform(-300,-300);
g.Clear(BackColor);
double
x1,
x2,
y1,
y2;
double
x,
y;
x1
=
System.Convert.ToSingle(textBox1.Text);
y1
=
System.Convert.ToSingle(textBox2.Text);
x2
=
System.Convert.ToSingle(textBox3.Text);
y2
=
System.Convert.ToSingle(textBox4.Text);
x
=
x1;
double
k
=
(y1
-
y2)
/
(x1
-
x2);
Color
color1
=
Color.FromArgb(255,
0,
0);
//定义颜色
Brush
bru1
=
new
SolidBrush(color1);//定义笔
Color
color2
=
Color.FromArgb(0,
255,
0);
//定义颜色
Brush
bru2
=
new
SolidBrush(color2);//定义笔
Pen
pen1
=
new
Pen(bru1,
1);
Pen
pen2
=
new
Pen(bru2,
1);
while
(x
<
x2)
{
//
textBox3.Text
=
System.Convert.ToString(k);
y
=
(double)k
*
(x
-
x1)
+
y1;
double
a;
a=y%1;
float
xx
=
Convert.ToSingle(x);
float
yy
=
Convert.ToSingle(y);
if
(a
>
0.5)
{
g.DrawLine(pen1,
xx,
yy,
xx,yy+1);
}
else
{
g.DrawLine(pen2,
xx,
yy,
xx,
yy+1);
}
x++;
}
//g.DrawLine(p,10,10,100,100);
}
private
void
button2_Click(object
sender,
EventArgs
e)
{
g.TranslateTransform(300,
300);
g.Clear(BackColor);
float
r;//r为圆的圆心
r
=System.Convert.ToSingle(textBox6.Text);
Color
color1
=
Color.FromArgb(255,
0,
0);
//定义颜色
Brush
bru1
=
new
SolidBrush(color1);//定义笔
Color
color2
=
Color.FromArgb(0,
255,
0);
//定义颜色
Brush
bru2
=
new
SolidBrush(color2);//定义笔
Pen
pen1
=
new
Pen(bru1,1);
Pen
pen2
=
new
Pen(bru2,
1);
float
x
=
0;
float
y
=
r;
while
(x
<r+3)
{
y
=
(float)System.Math.Sqrt(r
*
r
-
x
*
x);
float
a;
a
=
y
%
1;
y
=
y
-
a;
if
(a
>
0.5)
{
g.DrawLine(pen1,
x,
y,
x,
y+1);
g.DrawLine(pen1,
-x,
y,
-x,
y
+
1);
g.DrawLine(pen1,
x,
-y,
x,
-y
+
1);
g.DrawLine(pen1,
-x,
-y,
-x,
-y
+
1);
}
else
{
g.DrawLine(pen2,
x,
y,
x,
y+1);
g.DrawLine(pen2,
-x,
y,
-x,
y
+
1);
g.DrawLine(pen2,
x,-
y,
x,-
y
+
1);
g.DrawLine(pen2,
-x,
-y,-
x,
-y
+
1);
}
x++;
}
g.TranslateTransform(-300,
-300);
}
private
void
button3_Click(object
sender,
EventArgs
e)
{
}
private
void
comboBox1_SelectedIndexChanged(object
sender,
EventArgs
e)
{
switch
(comboBox1.Text)
{
case
"画圆":
{
textBox1.Visible
=
false;
textBox2.Visible
=
false;
textBox3.Visible
=
false;
textBox4.Visible
=
false;
textBox5.Visible
=
true;
textBox6.Visible
=
true;
textBox7.Visible
=
false;
textBox8.Visible
=
false;
label1.Visible
=
false;
label2.Visible
=
false;
label3.Visible
=
false;
label4.Visible
=
false;
label5.Visible
=
true;
label6.Visible
=
true;
label7.Visible
=
false;
label8.Visible
=
false;
label9.Visible
=
true;
button1.Visible
=
false;
button2.Visible
=
true;
button3.Visible
=
false;
break;
}
case"画线":
{
textBox1.Visible
=
true;
textBox2.Visible
=
true;
textBox3.Visible
=
true;
textBox4.Visible
=
true;
textBox5.Visible
=
false;
textBox6.Visible
=
false;
textBox7.Visible
=
false;
textBox8.Visible
=
false;
label1.Visible
=
true;
label2.Visible
=
true;
label3.Visible
=
true;
label4.Visible
=
true;
label5.Visible
=
false;
label6.Visible
=
false;
label7.Visible
=
false;
label8.Visible
=
false;
label9.Visible
=
false;
button1.Visible
=
true;
button2.Visible
=
false;
button3.Visible
=
false;
break;
}
case"画椭圆":
{
textBox1.Visible
=
false;
textBox2.Visible
=
false;
textBox3.Visible
=
false;
textBox4.Visible
=
false;
textBox5.Visible
=
false;
textBox6.Visible
=
false;
textBox7.Visible
=
true;
textBox8.Visible
=
true;
label1.Visible
=
false;
label2.Visible
=
false;
label3.Visible
=
false;
label4.Visible
=
false;
label5.Visible
=
false;
label6.Visible
=
false;
label7.Visible
=
true;
label8.Visible
=
true;
label9.Visible
=
false;
button1.Visible
=
false;
button2.Visible
=
false;
button3.Visible
=
true;
break;
}
}
}
}
}
敛波涛Ha
2008-09-26 · TA获得超过314个赞
知道答主
回答量:123
采纳率:0%
帮助的人:0
展开全部
lihangdnc ks
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
光明小神棍
2008-10-07
知道答主
回答量:34
采纳率:0%
帮助的人:0
展开全部
我连画圆的一块给你吧

需要橡皮筋 椭圆 树什么的可以和我说 我是用 c#写的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace line
{
public partial class Form1 : Form
{
Graphics g;

public Form1()
{
InitializeComponent();
g = pictureBox1.CreateGraphics();

}

private void button1_Click_1(object sender, EventArgs e)
{
// g.TranslateTransform(-300,-300);
g.Clear(BackColor);
double x1, x2, y1, y2;
double x, y;
x1 = System.Convert.ToSingle(textBox1.Text);
y1 = System.Convert.ToSingle(textBox2.Text);
x2 = System.Convert.ToSingle(textBox3.Text);
y2 = System.Convert.ToSingle(textBox4.Text);
x = x1;
double k = (y1 - y2) / (x1 - x2);
Color color1 = Color.FromArgb(255, 0, 0); //定义颜色
Brush bru1 = new SolidBrush(color1);//定义笔
Color color2 = Color.FromArgb(0, 255, 0); //定义颜色
Brush bru2 = new SolidBrush(color2);//定义笔
Pen pen1 = new Pen(bru1, 1);
Pen pen2 = new Pen(bru2, 1);
while (x < x2)
{
// textBox3.Text = System.Convert.ToString(k);
y = (double)k * (x - x1) + y1;
double a;
a=y%1;
float xx = Convert.ToSingle(x);
float yy = Convert.ToSingle(y);
if (a > 0.5)
{

g.DrawLine(pen1, xx, yy, xx,yy+1);

}
else
{
g.DrawLine(pen2, xx, yy, xx, yy+1);
}
x++;

}

//g.DrawLine(p,10,10,100,100);

}

private void button2_Click(object sender, EventArgs e)
{
g.TranslateTransform(300, 300);
g.Clear(BackColor);
float r;//r为圆的圆心
r =System.Convert.ToSingle(textBox6.Text);
Color color1 = Color.FromArgb(255, 0, 0); //定义颜色
Brush bru1 = new SolidBrush(color1);//定义笔
Color color2 = Color.FromArgb(0, 255, 0); //定义颜色
Brush bru2 = new SolidBrush(color2);//定义笔
Pen pen1 = new Pen(bru1,1);
Pen pen2 = new Pen(bru2, 1);
float x = 0;
float y = r;
while (x <r+3)
{
y = (float)System.Math.Sqrt(r * r - x * x);
float a;
a = y % 1;
y = y - a;
if (a > 0.5)
{
g.DrawLine(pen1, x, y, x, y+1);
g.DrawLine(pen1, -x, y, -x, y + 1);
g.DrawLine(pen1, x, -y, x, -y + 1);
g.DrawLine(pen1, -x, -y, -x, -y + 1);

}
else
{
g.DrawLine(pen2, x, y, x, y+1);
g.DrawLine(pen2, -x, y, -x, y + 1);
g.DrawLine(pen2, x,- y, x,- y + 1);
g.DrawLine(pen2, -x, -y,- x, -y + 1);

}
x++;

}
g.TranslateTransform(-300, -300);
}

private void button3_Click(object sender, EventArgs e)
{

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "画圆":
{

textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = true;
textBox6.Visible = true;
textBox7.Visible = false;
textBox8.Visible = false;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
label5.Visible = true;
label6.Visible = true;
label7.Visible = false;
label8.Visible = false;
label9.Visible = true;
button1.Visible = false;
button2.Visible = true;
button3.Visible = false;
break;

}
case"画线":
{
textBox1.Visible = true;
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
label8.Visible = false;
label9.Visible = false;
button1.Visible = true;
button2.Visible = false;
button3.Visible = false;
break;

}
case"画椭圆":
{
textBox1.Visible = false;
textBox2.Visible = false;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = true;
textBox8.Visible = true;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
label5.Visible = false;
label6.Visible = false;
label7.Visible = true;
label8.Visible = true;
label9.Visible = false;
button1.Visible = false;
button2.Visible = false;
button3.Visible = true;
break;

}

}

}

}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式