The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Brasenham Line Drawing Algorithm problem
Discuss Brasenham Line Drawing Algorithm problem in the C Programming forum on Dev Shed. Brasenham Line Drawing Algorithm problem C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 28th, 2012, 12:32 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 16
Time spent in forums: 7 h 5 sec
Reputation Power: 0
|
|
|
Brasenham Line Drawing Algorithm problem
Hello
I am try to learn Brasenham Line Drawing Algorithm. I wrote this program in Turbo C
Code:
# include <stdio.h>
# include <conio.h>
# include <graphics.h>
void main()
{
int dx,dy,x,y,p,x1,y1,x2,y2;
int gd,gm,errorcode;
clrscr();
printf("\n\n\tEnter the co-ordinates of first point : ");
scanf("%d %d",&x1,&y1);
printf("\n\n\tEnter the co-ordinates of second point : ");
scanf("%d %d",&x2,&y2);
dx = (x2 - x1);
dy = (y2 - y1);
p = 2 * (dy) - (dx);
x = x1;
y = y1;
gd=DETECT,gm,errorcode;
initgraph(&gd,&gm,"e:\\tc\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("%s",grapherrormsg(errorcode));
getch();return;
}
putpixel(x,y,WHITE);
while(x <= x2)
{
if(p < 0)
{
x=x+1;
y=y;
p = p + 2 * (dy);
}
else
{
x=x+1;
y=y+1;
p = p + 2 * (dy - dx);
}
putpixel(x,y,WHITE);
}
getch();
closegraph();
}
if I enter coordinates - 180,250,500,600 the output a line going diagnoly downwards, but if I enter 500,600,180,250 i am getting BLANK SCREEN.
Please explain if I'm wrong
|

November 28th, 2012, 05:06 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
I'll give you a hint. This line:
Guess what happens if x1 > x2? Your while loop is never entered in this case.
Also, it is spelled "Bresenham", so you should have no trouble finding good implementations of this algorithm.
Extra bonus. Why are you writing code like this:
Code:
gd=DETECT,gm,errorcode;
Do you even know what it does?
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|