Code for Program of Bresenham line drawing algorithm in C++ Programming

Posted By: Achchuthan Yogarajah - 7:33 AM

Share

& Comment

If we try out the C++ implementation of the Bresenham algorithm, we find it has some peculiar properties.
As expected, it fails to plot lines with negative slopes (try it and see what happens). It also fails to plot lines of positive slope greater than 1 (this is an interesting case, try it also and see if you can explain what is happening).
More unusually, we find that the order in which the endpoints are supplied to this routine is significant, it will only work as long as x1 is smaller than x2.
In fact, if we have two line segments with the same endpoints, and the same slope, this routine may draw one of them successfully but fails to draw the other one.
Of course, this is not surprising really, when we consider that the function works by incrementing x. It does emphasise, however, that the routine is plotting vectors, direction is significant. Considering all the vectors from(x1,y1) to (x2,y2) we find that there are eight regions, (the ``octants'') and the basic Bresenham algorithm works in only one of them.
Output of This Program :

About Achchuthan Yogarajah

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

0 comments :

Post a Comment

Copyright © 2016 C++ Examples ACHCHUTHAN.ORG. Designed by Templateism .