Results 1 to 3 of 3

Thread: question

  1. #1
    rajperimdad is offline Junior Member
    Last Online
    11th January 2011 @ 06:35 PM
    Join Date
    26 Nov 2010
    Age
    35
    Gender
    Male
    Posts
    4
    Threads
    1
    Credits
    0
    Thanked
    0

    Default question

    mujhe ise question ka answer chahi computer graphics ke subjects se. Q:describe the bresenhams' line drawing algorithm with its advantages over other line drawing algorithms?

    Reply

  2. #2
    ch_ttayyab's Avatar
    ch_ttayyab is offline Senior Member+
    Last Online
    28th September 2016 @ 07:09 PM
    Join Date
    21 Jul 2008
    Location
    Always Alone
    Gender
    Male
    Posts
    548
    Threads
    45
    Credits
    362
    Thanked
    24

    Default

    Pm Me For Cheap Voip Deals

  3. #3
    Zaara's Avatar
    Zaara is offline Advance Member
    Last Online
    26th December 2022 @ 06:33 PM
    Join Date
    24 Jun 2007
    Age
    36
    Gender
    Female
    Posts
    10,423
    Threads
    728
    Credits
    611
    Thanked
    1484

    Default

    The Bresenham line algorithm is an algorithm which determines which points in an n-dimensional raster should be plotted in order to form a close approximation to a straight line between two given points. It is commonly used to draw lines on a computer screen, as it uses only integer addition, subtraction and bit shifting, all of which are very cheap operations in standard computer architectures. It is one of the earliest algorithms developed in the field of computer graphics. A minor extension to the original algorithm also deals with drawing circles.

    While algorithms such as Wu's algorithm are also frequently used in modern computer graphics because they can support antialiasing, the speed and simplicity of Bresenham's line algorithm mean that it is still important. The algorithm is used in hardware such as plotters and in the graphics chips of modern graphics cards. It can also be found in many software graphics libraries. Because the algorithm is very simple, it is often implemented in either the firmware or the hardware of modern graphics cards.

    The algorithm
    Illustration of the result of Bresenham's line algorithm. (0,0) is at the top left corner.

    The common conventions that pixel coordinates increase in the down and right directions (e.g. that the pixel at (1,1) is directly above the pixel at (1,2)) and that the pixel centers that have integer coordinates will be used. The endpoints of the line are the pixels at (x0, y0) and (x1, y1), where the first coordinate of the pair is the column and the second is the row.

    The algorithm will be initially presented only for the octant in which the segment goes down and to the right (x0≤x1 and y0≤y1), and its horizontal projection x1 − x0 is longer than the vertical projection y1 − y0 (the line has a slope whose absolute value is less than 1 and greater than 0.) In this octant, for each column x between x0 and x1, there is exactly one row y (computed by the algorithm) containing a pixel of the line, while each row between y0 and y1 may contain multiple rasterized pixels.

    Bresenham's algorithm chooses the integer y corresponding to the pixel center that is closest to the ideal (fractional) y for the same x; on successive columns y can remain the same or increase by 1. The general equation of the line through the endpoints is given by:

    \frac{y - y_0}{y_1-y_0} = \frac{x-x_0}{x_1-x_0}.

    Since we know the column, x, the pixel's row, y, is given by rounding this quantity to the nearest integer:

    y = \frac{y_1-y_0}{x_1-x_0} (x-x_0) + y_0.

    The slope (y1 − y0) / (x1 − x0) depends on the endpoint coordinates only and can be precomputed, and the ideal y for successive integer values of x can be computed starting from y0 and repeatedly adding the slope.

    In practice, the algorithm can track, instead of possibly large y values, a small error value between −0.5 and 0.5: the vertical distance between the rounded and the exact y values for the current x. Each time x is increased, the error is increased by the slope; if it exceeds 0.5, the rasterization y is increased by 1 (the line continues on the next lower row of the raster) and the error is decremented by 1.0.

    In the following pseudocode sample plot(x,y) plots a point and abs returns absolute value:

    function line(x0, x1, y0, y1)
    int deltax := x1 - x0
    int deltay := y1 - y0
    real error := 0
    real deltaerr := deltay / deltax // Assume deltax != 0 (line is not vertical),
    // note that this division needs to be done in a way that preserves the fractional part
    int y := y0
    for x from x0 to x1
    plot(x,y)
    error := error + deltaerr
    if abs(error) ≥ 0.5 then
    y := y + 1
    error := error - 1.0

    [edit] Generalization

    The version above only handles lines that descend to the right. We would of course like to be able to draw all lines. The first case is allowing us to draw lines that still slope downwards but head in the opposite direction. This is a simple matter of swapping the initial points if x0 > x1. Trickier is determining how to draw lines that go up. To do this, we check if y0 ≥ y1; if so, we step y by -1 instead of 1. Lastly, we still need to generalize the algorithm to drawing lines in all directions. Up until now we have only been able to draw lines with a slope less than one. To be able to draw lines with a steeper slope, we take advantage of the fact that a steep line can be reflected across the line y=x to obtain a line with a small slope. The effect is to switch the x and y variables throughout, including switching the parameters to plot. The code looks like this:

    function line(x0, x1, y0, y1)
    boolean steep := abs(y1 - y0) > abs(x1 - x0)
    if steep then
    swap(x0, y0)
    swap(x1, y1)
    if x0 > x1 then
    swap(x0, x1)
    swap(y0, y1)
    int deltax := x1 - x0
    int deltay := abs(y1 - y0)
    real error := 0
    real deltaerr := deltay / deltax
    int ystep
    int y := y0
    if y0 < y1 then ystep := 1 else ystep := -1
    for x from x0 to x1
    if steep then plot(y,x) else plot(x,y)
    error := error + deltaerr
    if error ≥ 0.5 then
    y := y + ystep
    error := error - 1.0

    for more see it...

    http://en.wikipedia.org/wiki/Bresenh...line_algorithm

Similar Threads

  1. Solved Q21. ITD Winner Rank Question (Final Question)
    By Afridi in forum ITDunya 18th Anniversary (8 Nov 2023)
    Replies: 9
    Last Post: 8th November 2011, 10:09 PM
  2. Solved c++ question
    By shamsgul in forum Solved Problems (IT)
    Replies: 17
    Last Post: 11th July 2011, 01:17 AM
  3. new game question with question..........
    By lucky shah in forum Baat cheet
    Replies: 12
    Last Post: 16th July 2010, 02:53 AM
  4. a little question
    By esr in forum Ask an Expert
    Replies: 8
    Last Post: 10th October 2008, 12:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •