请教关于用c画直线的问题
昨天在一本书上看到一个程序,用c画一条斜度小于90度的直线,用的算法是逐点比较法,是在tc底下编译的,结果我今天在调试时实现不了,请高手指点一下,源代码如下:
#include "stdio.h"
#include "stdlib.h"
#include "graphics.h"
#include "math.h"
#define ESC 0×1b
void Initialize(void)
{
int GraphDriver;
int GraphMode;
int ErrorCode;
GraphDriver=DETECT;
initgraph(&GraphDriver,&GraphMode,"");
ErrorCode=graphresult();
if(ErrorCode!=grOK)
{
printf("Graphics System Error:%s\n",grapherrormsg(ErrorCode));
exit(1);
}
}
main()
{
int xo,yo,xa,ya,x,y;
int dx,dy,c,f; /* c为从原点o到点a要走的步数 */
Initialize();
printf("input x,y:");
scanf("%d,%d",&xo,&yo);
printf("xa:%d-639",xo);
scanf("%d",&xa);
printf("ya:0......%d",yo);
scanf("%d",&ya);
dx=xa-xo;dy=yo-ya;
if(xa>=xo&&xa<=639&&ya>=0&&ya<=yo)
{
outtextxy(xo,yo+5,"o");
outtextxy(xa,ya-10,"a");
if(dx>dy) c=dx;
else c=dy;
x=xo;y=yo;f=0;
while(c>=0)
{
putpixel(x,y,14);
if(f>0) {x=x+1;f=f-dy;if(dx>dy) c=c-1;}
else {y=y-1;f=f+dx;if(dx<=dy) c=c-1;}
}
}
else printf ("error");
}
p.s. “0×1b”中的×怎样在tc中加入阿,键盘上没这键阿
#include "stdio.h"
#include "stdlib.h"
#include "graphics.h"
#include "math.h"
#define ESC 0×1b
void Initialize(void)
{
int GraphDriver;
int GraphMode;
int ErrorCode;
GraphDriver=DETECT;
initgraph(&GraphDriver,&GraphMode,"");
ErrorCode=graphresult();
if(ErrorCode!=grOK)
{
printf("Graphics System Error:%s\n",grapherrormsg(ErrorCode));
exit(1);
}
}
main()
{
int xo,yo,xa,ya,x,y;
int dx,dy,c,f; /* c为从原点o到点a要走的步数 */
Initialize();
printf("input x,y:");
scanf("%d,%d",&xo,&yo);
printf("xa:%d-639",xo);
scanf("%d",&xa);
printf("ya:0......%d",yo);
scanf("%d",&ya);
dx=xa-xo;dy=yo-ya;
if(xa>=xo&&xa<=639&&ya>=0&&ya<=yo)
{
outtextxy(xo,yo+5,"o");
outtextxy(xa,ya-10,"a");
if(dx>dy) c=dx;
else c=dy;
x=xo;y=yo;f=0;
while(c>=0)
{
putpixel(x,y,14);
if(f>0) {x=x+1;f=f-dy;if(dx>dy) c=c-1;}
else {y=y-1;f=f+dx;if(dx<=dy) c=c-1;}
}
}
else printf ("error");
}
p.s. “0×1b”中的×怎样在tc中加入阿,键盘上没这键阿
...全文
相关推荐
用C语言实现DDA算法画直线
DDA(Digital Differential Analyzer)算法是一种简单且直观的画直线的方法,主要用于计算机图形学中。在C语言中实现DDA算法可以帮助我们理解计算机如何在屏幕上绘制直线。
DDA、Bresenham、Midpoint算法画直线
在计算机图形学中,画直线是一项基础且重要的任务。
线段、射线、直线(提高)巩固练习.doc
蚂蚁的最短路径:蚂蚁从A到C的最短路径通常是直接从A到C的线段。16. 握手问题:这是一个组合问题,n个人握手,每个人都要和其他n-1个人握手一次,总握手次数为n(n-1)/2。17.
用VC画直线
由Jack Elton Bresenham于1965年提出的这个算法,是为了解决在像素化的显示设备上高效地画出直线的问题。
六年级数学下册第七章相交线与平行线2探索直线平行的条件课件鲁教版五四制20200327145
例如,如果已知直线b平行于直线d,同时直线c也平行于直线d,根据平行线的传递性,我们可以推断出直线b与直线c也是平行的。这个性质在解决更复杂的几何问题时非常有用。


