PDA

View Full Version : رسم خط توسط آلگوریتم DDA



AccessFull
چهارشنبه 07 فروردین 1387, 17:23 عصر
سلام دوستان من یه برنامه میخوام که با استفاده از الگوریتم DDA خط رسم کنه اگه میشه
C , VB 6 باشه ....

BOB
پنج شنبه 08 فروردین 1387, 10:55 صبح
سلام

انواع الگوریتمهای ترسیم خط مثل DDA,Bresenham,... به زبان جاوا :
http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html

موفق باشید

AccessFull
پنج شنبه 08 فروردین 1387, 14:29 عصر
خودم امروز نوشتم ..... دوستان استفاده کنن . در ضمن برزنهام هم توش هست ....


#include <graphics.h>
#include <conio.h>
#include <stdlib.h>

void splash(void);

int main(void)
{
splash();
int x1,y1,x2,y2,dx,dy,step,xinc,yinc,x,y,i,d2y,d2yx;
clrscr();
cprintf("Enter X1:");
cscanf("%d",&x1);
cprintf("\r\nEnter Y1:");
cscanf("%d",&y1);
cprintf("\r\nEnter X2:");
cscanf("%d",&x2);
cprintf("\r\nEnter Y2:");
cscanf("%d",&y2);
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
if (graphresult()!= grOk)
{
cprintf("Graphics error: %s\r\n", grapherrormsg(errorcode));
cprintf("Press any key to halt:");
getch();
exit(1);
}
outtextxy(1,1,"DDA Alguritm");
setcolor(4);
line(x1,y1,x2,y2);
setcolor(15);
dx=x2-x1;
dy=y2-y1;
if (x2>x1)
step=abs(dx);
else
step=abs(dy);
xinc=dx/step;
yinc=dy/step;
x=x1;
y=y1;
for (i=1;i<=step;i++)
{
putpixel(x,y,15);
x+=xinc;
y+=yinc;
}
getch();
getch();
cleardevice();
outtextxy(1,1,"Bersenham Alguritm");
setcolor(4);
line(x1,y1,x2,y2);
setcolor(15);
x=x1;
y=y1;
d2y=2*dy;
d2yx=2*dy-dx;
for(i=0;i<=dx;i++)
{
putpixel(x,y,15);
if (d2yx<0)
{
x++;
d2yx+=d2y;
}
else
{
x++;
y++;
d2yx+=(d2y-2*dx);
}
}
getch();
getch();
closegraph();
return 0;
}
void splash(void)
{
textmode(C80);
clrscr();
cprintf("Date:27/03/2008\r\n");
cprintf("Comments:This program draw a line with DDA and Bersenham alguritme.\r\n");
cprintf("Access Full Cont\r\n");
cprintf("360.yahoo.com/S_E_Loghman");
gotoxy(1,25);
cprintf("Press any key to continue ...");
getch();
}

saharr
دوشنبه 06 آبان 1387, 14:16 عصر
درود

اين كد DDA رو وقتي تو TC اجرا مي كنم، خطا زير را اعلام مي كند

BGI Error:graphics not initialized(use initgraph)

راه حل چيه؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟؟؟؟؟؟؟؟

D32.00110
دوشنبه 06 آبان 1387, 22:04 عصر
درود

اين كد DDA رو وقتي تو TC اجرا مي كنم، خطا زير را اعلام مي كند

BGI Error:graphics not initialized(use initgraph)

راه حل چيه؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟؟؟؟؟؟؟؟

مسیر کتابخانه ها درست نیست دقیق یادم نیست فکر کنم از option > directory میشه درست کرد ...
یادش بخیر :لبخند:

parisa123
سه شنبه 02 آذر 1389, 12:14 عصر
#include<graphics.h>
#include <stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<math.h>
#include<dos.h>
int main()
{
float x,y,x1,y1,x2,y2,step,color,xinc,yinc,m;
int i,gdriver = DETECT, gmode, errorcode;
clrscr();
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi\\");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
cout<<"x1=";
cin>>x1;
cout<<"y1=";
cin>>y1;
cout<<"x2=";
cin>>x2;
cout<<"y2=";
cin>>y2;
cout<<"colour=";
cin>>color;
if(x1==x2)
{
for(int i=y1;i<=y2;i++)
{
putpixel(x1,i,color);
cout<<"("<<x1<<","<<i<<")"<<endl;
} }
else
{
if(x1<x2)
{
x=x1;
y=y1;
}
else
{
x=x2;
y=y2;
}
m=float((y2-y1)/(x2-x1));
if(fabs(m)<1)
{
xinc=1;
yinc=m;
step=fabs(x2-x1);
}
else
{
xinc=1/m;
yinc=1;
step=fabs(y2-y1);
}
cout<<"m="<<m<<endl;
cout<<"xinc="<<xinc<<endl;
cout<<"yinc="<<yinc<<endl;

for(i=1;i<=step+1;i++)
{
putpixel(x,y,color);
cout<<"("<<x<<","<<y<<")"<<endl;
x=x+xinc;
y=y+yinc;
delay(2);
}
}
getch();
closegraph();
return(0);
}