November 28th, 2012, 12:32 AM
Brasenham Line Drawing Algorithm problem
I am try to learn Brasenham Line Drawing Algorithm. I wrote this program in Turbo C
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.
# include <stdio.h>
# include <conio.h>
# include <graphics.h>
printf("\n\n\tEnter the co-ordinates of first point : ");
printf("\n\n\tEnter the co-ordinates of second point : ");
dx = (x2 - x1);
dy = (y2 - y1);
p = 2 * (dy) - (dx);
x = x1;
y = y1;
while(x <= x2)
if(p < 0)
p = p + 2 * (dy);
p = p + 2 * (dy - dx);
Please explain if I'm wrong
November 28th, 2012, 05:06 AM
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:
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
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo