資源簡介
1. 完成坐標(biāo)變換,將坐標(biāo)原點(diǎn)移動到(400,300)處,并使X軸正方向水平向右,使Y軸正方向垂直向上(原來的坐標(biāo)原點(diǎn)位于繪圖區(qū)的左上角且Y軸正方向是朝下的);
2. 分別實(shí)現(xiàn)數(shù)值微分算法和Bresenham算法,不能使用系統(tǒng)API生成直線而只能使用SetPixel函數(shù)。

代碼片段和文件信息
//?Line.cpp:?implementation?of?the?Line?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“The2.h“
#include?“Line.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
Line::Line()
{
}
Line::~Line()
{
}
void?Line::Bresenham(CDC?*pDC)???????//Bresenham算法
{
int?xyez;
dx=x2-x1dy=y2-y1e=-dxx=x1y=y1;
int?ux?=?((dx?>?0)?<1)?-?1;//x的增量方向,取或-1
int?uy?=?((dy?>?0)?<1)?-?1;//y的增量方向,取或-1
z?=?0;dx?=?abs(dx);?dy?=?abs(dy);
if?(dx>dy)
{
for?(x=x1;x!=x2;x+=ux)
{
pDC->SetPixel(xyCOLORREF(RGB(redgreenblue)));
z+=dy;
if((z<<1)>=dx)
{
y+=uy;z-=dx;
}
}
}
else
{
for(y=y1;y!=y2;y+=uy)
{
????pDC->SetPixel(xyCOLORREF(RGB(redgreenblue)));
z+=dx;
if((z<<1)>=dy)
{
x+=ux;z-=dy;
}
}
}
}
void?Line::DDA(CDC?*pDC)?????????//數(shù)值微分算法
{
int?x;
float?dxdyykab;
if(x2 ????a=x2;
x2=x1;
x1=a;
b=y2;
y2=y1;
y1=b;
}
dx=x2-x1dy=y2-y1;
k=dy/dxy=y1;
for(x=x1;x<=x2;x++){???????//?X每次加1,Y加K
???????pDC->SetPixel(xyCOLORREF(RGB(redgreenblue)));
???y=y+k;
}
}
void?Line::CS(CDC?*pDC)?????//繪制坐標(biāo)系
{
int?i;
CString?temp;
????pDC->MoveTo(-4000);???//畫X軸
pDC->LineTo(5000);
pDC->MoveTo(0400);????//畫Y軸
pDC->LineTo(0-400);
pDC->MoveTo(-8292);????//畫小箭頭
pDC->LineTo(0300);
pDC->LineTo(8292);
pDC->MoveTo(492-8);
pDC->LineTo(5000);
pDC->LineTo(4928);
????
for(i=-350;i<500;i=i+50)?????//畫數(shù)字小標(biāo)
{
temp.Format(“%d“i);
pDC->MoveTo(i0);
pDC->LineTo(i5);
pDC->TextOut(i-10-5temp);
}
for(i=-350;i<400;i=i+50){
temp.Format(“%d“i);
pDC->MoveTo(0i);
pDC->LineTo(5i);
if(i!=0){
pDC->TextOut(-30itemp);
}
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????8952??2013-10-15?23:44??The2\Debug\Line.obj
?????文件??????????0??2013-10-15?23:45??The2\Debug\Line.sbr
?????文件??????11277??2013-10-15?23:17??The2\Debug\LineDlg.obj
?????文件??????????0??2013-10-15?23:17??The2\Debug\LineDlg.sbr
?????文件??????20020??2013-10-15?20:35??The2\Debug\MainFrm.obj
?????文件??????????0??2013-10-15?20:35??The2\Debug\MainFrm.sbr
?????文件?????105709??2013-10-15?20:35??The2\Debug\StdAfx.obj
?????文件????1374998??2013-10-15?20:35??The2\Debug\StdAfx.sbr
?????文件????3671040??2013-10-15?23:45??The2\Debug\The2.bsc
?????文件?????122954??2013-10-15?23:45??The2\Debug\The2.exe
?????文件?????335448??2013-10-15?23:45??The2\Debug\The2.ilk
?????文件??????22954??2013-10-15?21:00??The2\Debug\The2.obj
?????文件????6881504??2013-10-15?20:35??The2\Debug\The2.pch
?????文件?????476160??2013-10-15?23:45??The2\Debug\The2.pdb
?????文件???????8004??2013-10-15?20:35??The2\Debug\The2.res
?????文件??????????0??2013-10-15?21:00??The2\Debug\The2.sbr
?????文件??????14723??2013-10-15?20:35??The2\Debug\The2Doc.obj
?????文件??????????0??2013-10-15?20:35??The2\Debug\The2Doc.sbr
?????文件??????24262??2013-10-15?23:27??The2\Debug\The2View.obj
?????文件??????????0??2013-10-15?23:27??The2\Debug\The2View.sbr
?????文件?????222208??2013-10-15?23:45??The2\Debug\vc60.idb
?????文件?????364544??2013-10-15?23:44??The2\Debug\vc60.pdb
?????文件???????2118??2013-10-16?00:39??The2\Line.cpp
?????文件????????655??2013-10-15?20:58??The2\Line.h
?????文件???????1298??2013-10-15?23:17??The2\LineDlg.cpp
?????文件???????1300??2013-10-15?21:00??The2\LineDlg.h
?????文件???????2505??2013-10-02?10:57??The2\MainFrm.cpp
?????文件???????1581??2013-10-02?10:57??The2\MainFrm.h
?????文件???????4263??2013-10-02?10:57??The2\ReadMe.txt
?????文件???????1078??2013-10-02?10:57??The2\res\The2.ico
............此處省略26個文件信息
評論
共有 條評論