导航:首页 > 源码编译 > 直线算法

直线算法

发布时间:2022-01-13 16:31:32

㈠ 回归直线算法

y等于x份之k才对吧!

㈡ 角度转直线算法

直线倾斜的角度在解析几何中称为斜率,为直线与X轴所成角度α的正切值用k表示,即tanα=k
已知a(x1,y1) b(x2,y2),则k=(y1-y2)/(x1-x2)
∵a(x=10,y=10) b(x=100,y=100)
∴k=(100-10)/(100-10)=1
∴直线倾斜的角度是45º

㈢ 已知两点的坐标,求直线的算法

易知 方程斜率为k=(x1-x2)/(y1-y2) 又直线过(x1,y1) 则直线方程是y-y1=(x1-x2)/(y1-y2)(x-x1) 然后在整理下就可以了

㈣ 拟合直线算法

你没有给数据啊。

输入x和y,然后选择上交所拟合类型1线性2二次
然后方误差由下式给出

㈤ Bresenham直线算法的一般化

虽然以上的算法只能绘画由右上至左下,且斜率小于或等于1的直线,但我们可以扩展此算法,使之可绘画任何的直线。第一个扩展是绘画反方向,即由左下至右上的直线。这可以简单地透过在x0 > x1时交换起点和终点来做到。第二个扩展是绘画斜率为负的直线。可以检查y0 ≥ y1是否成立;若该不等式成立,误差超出0.5时y的值改为加-1。最后,我们还需要扩展该算法,使之可以绘画斜率绝对值大于1的直线。要做到这点,我们可以利用大斜率直线对直线y=x的反射是一条小斜率直线的事实,在整个计算过程中交换 x 和 y,并一并将plot的参数顺序交换。扩展后的伪代码如下:
function line(x0, x1, y0, y1)
boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x0
int deltay := abs(y1 - y0)
real error := 0
real deltaerr := deltay / deltax
int ystep
int y := y0
if y0 < y1 then ystep := 1 else ystep := -1
for x from x0 to x1
if steep then plot(y,x) else plot(x,y)
error := error + deltaerr
if error ≥ 0.5 then
y := y + ystep
error := error - 1.0
以上的程序可以处理任何的直线,实现了完整的Bresenham直线算法。

㈥ 利用C语言编写 能够画出任意的直线算法程序(利用画点函数)

上次刚写过,在VC下运行的,
int dx,dy,incrE,incrNE,d,x,y;

if ((point[1].x-point[0].x)==0){ //垂直的直线
x=point[0].x;
for(y=point[0].y;y<point[1].y;y++)
pDC->SetPixel(x,y,50);
}
else if(abs((point[1].y-point[0].y)/(point[1].x-point[0].x))<=1){ //斜率 -1到 1 之间
dx=point[1].x-point[0].x;
dy=point[0].y-point[1].y;
d=dx-2*dy;

incrE=-2*dy;
incrNE=2*(dx-dy);
x=point[0].x,y=point[0].y;
pDC->SetPixel(x,y,50);
if(point[0].y>point[1].y){
while(x<point[1].x)
{
if(d>=0){
d+=incrE;
x++;
}
else
{d+=incrNE;
x++;
y--;
}
pDC->SetPixel(x,y,50);
}
}
else if(point[0].y<=point[1].y){
dy=point[1].y-point[0].y;
incrE=-2*dy;
incrNE=2*(dx-dy);
x=point[0].x,y=point[0].y;
pDC->SetPixel(x,y,50);
while(x<point[1].x)
{
if(d>=0){
d+=incrE;
x++;
}
else
{d+=incrNE;
x++;
y++;
}
pDC->SetPixel(x,y,50);
}
}
}
else { //斜率 <-1 和 >1的直线
if(point[1].x>=point[0].x){
dx=point[1].x-point[0].x;
dy=point[1].y-point[0].y;
d=2*dx-dy;
incrE=2*dx;
incrNE=2*(dx-dy);
x=point[0].x,y=point[0].y;
pDC->SetPixel(x,y,50);
while(x<point[1].x)
{
if(d<0){
d+=incrE;

y++;

}
else
{d+=incrNE;
pDC->SetPixel(x,y,50);
x++;
y++;
}
pDC->SetPixel(x,y,50);
}
}
else if((point[1].y-point[0].y)/(point[1].x-point[0].x)<-1){
dx=point[1].x-point[0].x;
dy=point[0].y-point[1].y;
d=2*dx-dy;
incrE=2*dx;
incrNE=2*(dx-dy);
x=point[0].x,y=point[0].y;
pDC->SetPixel(x,y,50);
while(y<point[1].y)
{
if(d>0){
d+=incrE;
y++;

}
else
{d+=incrNE;
x--;
y++;
}
pDC->SetPixel(x,y,50);
}

}

}

㈦ Bresenham直线算法的介绍

Bresenham直线算法是用来描绘由两点所决定的直线的算法,它会算出一条线段在 n 维光栅上最接近的点。这个算法只会用到较为快速的整数加法、减法和位元移位,常用于绘制电脑画面中的直线。是计算机图形学中最先发展出来的算法。

㈧ 求反走样直线算法

请看这个。。在MFC建立EXE即可void Mbline();
void AntDisline();double m_x0,m_y0,m_x1,m_y1;#include"InputDlg.h"
#define ROUND(a) int(a+0.5)void CTestView::Mbline()//走样函数直线
{
CClientDC dc(this);
COLORREF rgb=RGB(0,0,0);
x=m_x0;y=m_y0;k=(m_y1-m_y0)/(m_x1-m_x0);
d=0.5-k;
for(x=x0;x<=x1;x++)
{
if(d<0)
{
y++;
d+=1-k;
}
else
d-+k;
}
dc.TestOut(10,10,"走样直线");
}
void CTestView::AntiDisline()//距离加权反走样直线
{
CClientDC dc(this);
double x,y,d,k;
k=(y1-y0)/(x1-x0);
d=0;x=x0+10;y=y0+10;
COLORREF rgb1=RGB(0,0,0),rgb2=RGB(0,0,0);
for(x=x0;x<=(x1+10);x++)
{
rgb1=RGB(d*255,d*255,d*255);
rgb2=RGB((1-d)*255,(1-d)*255,(1-d)*255);
dc.SetPixel(ROUND(X),ROUND(Y+1),rgb2);
d+=k;
if(d>1.0)
{
y++;
d--;
}
}
dc.TestOut(10,100,"反走样直线");
}
void CTestView::OnMENUAntiliasing()
{
InputDlg dlg;
if(dlg.DoModal()==IDOK)

{
x0=dig.m_x0;
y0=dig.m_y0;
x1=dig.m_x1;
y1=dig.m_y1;
}
AfxGetMainWnd()->SetWindowTest("反走样:直线距离权反走样算法");
RedrawWindow();
Mbline();
AntiDisline();
}

㈨ 直线和圆的生成算法

看不懂

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

我连画圆的一块给你吧
需要橡皮筋
椭圆
树什么的可以和我说
我是用
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;
}
}
}
}
}

阅读全文

与直线算法相关的资料

热点内容
pythonzmq模式 浏览:180
linux运行php网站 浏览:865
实验室无油压缩机 浏览:805
哪里可以免费看动画app 浏览:53
文本加密咋解 浏览:485
tomcat做服务器怎么设置 浏览:252
非对称加密会增大网络包吗 浏览:703
为什么不能编译c 浏览:261
数据服务器不能启动是什么意思 浏览:556
java以什么开头 浏览:820
苹果手机相册文件夹如何清理 浏览:405
服务器云电脑搭建教程 浏览:410
eco怎么搭建服务器 浏览:468
周转材料核算法 浏览:356
学nodejs还是php好 浏览:279
电信营业厅app怎么买q币 浏览:917
linux退出登陆 浏览:534
python查找相似图片的代码 浏览:336
赵丽pdf 浏览:661
如何苹果手机app不要自动更新 浏览:979