c语言写一个画直线函数 用c语言画一条线

C语言编程个人认为只要不在同一直线的三点都能构成三角形 。
只要检测三点X 或Y 坐标是否相等c语言写一个画直线函数,如相等就不能构成三角形,反之可以 。
调用画直线函数,画三条直线即可 。
#includestdio.h
#includegraphics.h
void main(void){
int gd=DETECT,gm;
int x,x1,y,y1,x2,y2,maxx,maxy,flag,k,key,speed;
printf("\nEnter axis a: ");
scanf("%d%d",x,y);
getchar();
printf("\nEnter axis b: ");
scanf("%d%d",x1,y1);
getchar();
printf("\nEnter axis c: ");
scanf("%d%d",x2,y2);
getchar();
if((x==x1x1==x2x2==x)||(y==y1y1==y2y2==y)){
printf("\nCan not struct three angle.");
getchar();
}
else
{
initgraph(gd,gm,"改成c语言写一个画直线函数你的TC下BGI 路径");
setcolor(RED);
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
}
getchar();
closegraph();
}
怎么用C语言画一条红色的直线首先设置初始坐标和结束坐标,然后设定画线颜色,最后用draw函数画出来就好了
C绘制直线你用一个定时器,每隔你需要的一段时间就显示一个点,一直把直线上所有点显示完为止,这不就是你说的动态画线了?
c语言编程画直线y=45x-14的图像C语言编程,编写输出Y=X*X的抛物线图像 , 要求程序能输出图像,
#include"graphics.h"
#include"stdio.h"
main()
{
int graphdriver,graphmode;
int y,x,i;
graphdriver=DETECT;
initgraph(graphdriver,graphmode,"");
cleardevice();
setcolor(12);
line(100,200,500,200); /*x轴*/
line(300,400,300,400); /*y轴*/
for(i=-150;i150;i)
{
x=i;
y=x*x;
putpixel(300 x, 200-y/150, 5);/*画曲线*/
}
getch();
closegraph();
}
C语言画直线和填充的程序,要有算法的c 画的指针式 Roma 表
#include dos.h
#include stdio.h
#include math.h
#include graphics.h
void drawhourbrick(int x, int y, int color, float arg);
void drawminutebrick(int x, int y, int color, float arg);
void drawsecondbrick(int x, int y, int color, float arg);
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle);
int main()
{
int GraphDriver;
int GraphMode;
float arg = 292.5;
float hourarg = 0;
float minuterarg = 0;
float secondrarg = 0;
char buffer[10];
int a, b;
int x, y, r;
int h;
int xmo[12] = {1, 2, -6, -1, -1, -2, -2, -1, 0, -4, -4, -5};
int ymo[12] = {-1, -2, -1, -1, -1, -5, 2, 1, -2, -4, -4, 0};
long delay;
float degree;
struct time time, time1;
GraphDriver = DETECT;
initgraph(GraphDriver, GraphMode, "");
x = 300;
y = 220;
r = 200;
degree = atan(1) / 45;
polygon(8, x, y, r, 12, arg, 0);
polygon(8, x, y, r - 2, 11, arg, 0);
polygon(8, x, y, r - 4, 14, arg, 0);
setcolor(12);
/*settextstyle(DEFAULT_FONT, 1, 0);*/
for (a = 0; a12; a)
{
sprintf(buffer, "%d", a1);
outtextxy(x(r - 22) * cos((a - 2) * 30 * degree)xmo[a], y(r - 22) * sin((a - 2) * 30 * degree)ymo[a], buffer);
}
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
while(1)
{
gettime(time);
if (time.ti_hour != time1.ti_hour || time.ti_min != time1.ti_min || time.ti_sec != time1.ti_sec)
{
h = time.ti_hour;
if (h12)
h -= 12;
drawhourbrick(x, y, 0, hourarg);
drawminutebrick(x, y, 0, minuterarg);
drawsecondbrick(x, y, 0, secondrarg);
hourarg = (h % 12) * 30time.ti_min * 0.5time.ti_sec * 0.1 / 60;
minuterarg = time.ti_min * 6time.ti_sec * 0.1;
secondrarg = time.ti_sec * 6;
setcolor(8);
outtextxy(x - 15, y120, "Roma");
drawhourbrick(x, y, 14, hourarg);
drawminutebrick(x, y, 9, minuterarg);
drawsecondbrick(x, y, 13, secondrarg);
time1 = time;
}
while(kbhit())
{
a = getch();
if (a == 27)
{
closegraph();
return 0;
}
}
}
}
void polygon(int n, int x, int y, int r, int color, float arg, int fillstyle)
{
double pi;
int i;
float x1[9], y1[9];
setcolor(color);
pi = atan(1) * 4;
arg = atan(1) / 45 * arg;
x1[1] = xr * cos(2 * pi / narg);
y1[1] = yr * sin(2 * pi / narg);
moveto(x1[1], y1[1]);
for (i = 2; i = n; i)
{
x1[i] = xr * cos(2 * pi * i / narg);
y1[i] = yr * sin(2 * pi * i / narg);
lineto(x1[i], y1[i]);
}
lineto(x1[1], y1[1]);
if (fillstyle != 0)
{
setfillstyle(SOLID_FILL, color);
floodfill(x, y, color);
}
}
void drawhourbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x20 * cos(pi * (arg - 90 - 23));
y1[1] = y20 * sin(pi * (arg - 90 - 23));
x1[2] = x25 * cos(pi * (arg - 9023));
y1[2] = y25 * sin(pi * (arg - 9023));
x1[3] = x120 * cos(pi * (arg - 900));
y1[3] = y120 * sin(pi * (arg - 900));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0]x1[3]) / 2, (y1[0]y1[3]) / 2, color);
*/
}
void drawminutebrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
【c语言写一个画直线函数 用c语言画一条线】 x1[1] = x20 * cos(pi * (arg - 90 - 23));
y1[1] = y20 * sin(pi * (arg - 90 - 23));
x1[2] = x25 * cos(pi * (arg - 9023));
y1[2] = y25 * sin(pi * (arg - 9023));
x1[3] = x160 * cos(pi * (arg - 900));
y1[3] = y160 * sin(pi * (arg - 900));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0]x1[3]) / 2, (y1[0]y1[3]) / 2, color);
*/
}
void drawsecondbrick(int x, int y, int color, float arg)
{
double pi;
int i;
float x1[4], y1[4];
setcolor(color);
pi = atan(1) / 45;
x1[0] = x;
y1[0] = y;
x1[1] = x20 * cos(pi * (arg - 90 - 6));
y1[1] = y20 * sin(pi * (arg - 90 - 6));
x1[2] = x25 * cos(pi * (arg - 906));
y1[2] = y25 * sin(pi * (arg - 906));
x1[3] = x160 * cos(pi * (arg - 900));
y1[3] = y160 * sin(pi * (arg - 900));
moveto(x1[1], y1[1]);
lineto(x1[0], y1[0]);
lineto(x1[2], y1[2]);
lineto(x1[3], y1[3]);
lineto(x1[1], y1[1]);
setfillstyle(SOLID_FILL, color);
/*
floodfill((x1[0]x1[3]) / 2, (y1[0]y1[3]) / 2, color);
*/
}
根据两点画出直线,cwindows编程 函数 。帮忙实现CDC类不是有现成的函数么?
CDC *pdc = CDC::FromHandle(hdc);
pdc-MoveTo(ps);
pdc-LineTo(pe);
以下是引用:
直线段的扫描转换算法
1 数值微分(DDA)法
我的理解就是以一个坐标轴为步长值(增量为1)c语言写一个画直线函数,另一个坐标根据直线的斜率(K)为
增量c语言写一个画直线函数,然后四舍五入进行计算机,确定每一个点的坐标 。
具体算法(我用OPENGL模拟)
void setPixel(GLint xCoord,GLint yCoord)
{
glBegin(GL_POINTS);
glVertex2i(xCoord,yCoord);
glEnd();
}
inline int round(const float a)
{
return int(a 0.5);
}
void lineDDA(int x0,int y0,int xEnd,int yEnd)
{
int dx = xEnd - x0,dy = yEnd - y0,steps,k;
float xIncrement,yIncrement,x = x0,y=y0;
if(abs(dx)abs(dy))
{
steps = abs(dx);
}
else
{
steps = abs(dy);
}
xIncrement = float(dx)/float(steps);
yIncrement = float(dy)/float(steps);
setPixel(round(x),round(y));
for(k= 0;ksteps;k)
{
x =xIncrement;
y =yIncrement;
setPixel(round(x),round(y));
}
}
2中点画线法
同样我理解的算法就是,以一个增量为多的坐标轴为步长值(为1),而另一个坐标
值是加1,还是不变取决于这两个坐标值中点是在这条直线的上方,还是下方 。
具体算法如下:
void lineMiddle(int x0,int y0,int xEnd,int yEnd)
{
int a,b,c,d1,d2,d;
a = y0-yEnd;
b = xEnd-x0;
d = 2*a b;//判别试(2a b为初始值)
d1 = 2*a;//中点在直线下方增量值
d2 = 2*a b;//中点在真线上方的增量值
int x,y;
x = x0;y=y0;
setPixel(x,y);
while(xxEnd)
{
if(d0)//中点在直线下方
{
x;
y;
d =d2;
}
else//中点在直线上方
{
x;
d =d1;
}
setPixel(x,y);
}
}
3.Bresenham画线算法程序:
用一个坐标轴来当步长值(即 1) , 另一个坐标轴是否加1则跟据斜率(k)来确定 , K
如果大于0.5,那么也加 1,如果小于0.5那么即不变 。为了方便计算,如果d大于1
,那么就减一,归0 。可设e,e=d-0.5,于是就有e0时,加1,e0时不变,这样便
于硬件实现 。
算法实现如下:
void lineBresenham(int x0,int y0,int x1,int y1)
{
int x,y,dx,dy;
float k,e;
dx = x1 - x0;
dy = y1 - y0;;
k = (float)dy/dx;
e = -0.5;
x = x0;
y = y0;
setPixel(x,y);
for(int i =0;idx;i)
{
x = x 1;
e = e k;
if(e=0)
{
y;
e = e-1;
}
setPixel(x,y);
}
}
c语言写一个画直线函数的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于用c语言画一条线、c语言写一个画直线函数的信息别忘了在本站进行查找喔 。

    推荐阅读