Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Is this right? (bresenham)

Author
Message
NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 12th Sep 2009 03:26 Edited at: 12th Sep 2009 03:27
Here's a link to an "optimised" Bresenham line drawing algorithm on Wikipedia.

http://en.wikipedia.org/wiki/Bresenham's_line_algorithm#Optimization

At the beginning, it creates a bool called steep, and if it is true it swaps the X&Y. Then, there's another if statement during the plotting routine which swaps them right back.

Why?

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Sep 2009 07:00
It looks fine to me. It only swaps back if x0 is greater than x1. It wants to keep x1 as the larger number.

Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 12th Sep 2009 07:13
I believe he is referring to:



and then



IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Sep 2009 13:04
Quote: "Why?"

Because if it didn't pick the greater range for driving the loop, it would print a line of separated dots.

Implement the code as it has described and prove that it works at all line angles, then comment out that first step and run it again and you'll see the difference.

NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 12th Sep 2009 13:08
Hmm, I see. It needs to swap them around for the calculations but needs them in x:y format for plotting the point. Thanks.

Login to post a reply

Server time is: 2025-05-26 00:53:51
Your offset time is: 2025-05-26 00:53:51