Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:26:05+00:00 2026-06-18T00:26:05+00:00

There is this well known algorithm for drawing lines by Bresenham, Wikipedia has very

  • 0

There is this well known algorithm for drawing lines by Bresenham, Wikipedia has very good article about it: http://en.wikipedia.org/wiki/Bresenham’s_line_algorithm.

The main loop iteratively calculates x or y coordinates by adding or subtracting 1 as needed.

Given start-point x1, y1, end-point x2, y2 and some y (y1 <= y <= y2), is it possible to directly calculate all the x coordinates of active pixels at row y?

For example, imagine I draw a line using standard Bresenham method:

    oooo               - y1
        ooo
           oooo
               ooo     - y
                  oooo - y2

    |                |
    x1               x2

So for that y I would like to get a sequence of [x1+11, x1+12, x1+13].

I’m not sure if it is even possible to modify Bresenham as above so if it turns out it is not possible, is there any other way for getting the sequence which looks exactly the same as if it was calculated by Bresenham? I don’t care whether it is fast or slow, if it uses floats or not, as long as it can be evaluated directly.

Thanks in advance!

Edit: to be able to compare the ideas I wrote a simple reference test:

def line(x0, y0, x1, y1):
    canvas = [[u'\u25a1'] * (max(x0, x1) + 1) for y in range(max(y0, y1) + 1)]
    dx = abs(x1-x0)
    dy = abs(y1-y0)
    if x0 < x1:
        sx = 1
    else:
        sx = -1
    if y0 < y1:
        sy = 1
    else:
        sy = -1
    err = dx-dy
    while True:
        canvas[y0][x0] = u'\u25a0'
        if x0 == x1 and y0 == y1:
            break
        e2 = 2*err
        if e2 > -dy:
            err = err - dy
            x0 = x0 + sx
        if e2 < dx:
            err = err + dx
            y0 = y0 + sy
    return '\n'.join(' '.join(r) for r in canvas)

Typing:

print line(2, 1, 10, 8)

prints:

□ □ □ □ □ □ □ □ □ □ □
□ □ ■ □ □ □ □ □ □ □ □
□ □ □ ■ □ □ □ □ □ □ □
□ □ □ □ ■ □ □ □ □ □ □
□ □ □ □ □ ■ ■ □ □ □ □
□ □ □ □ □ □ □ ■ □ □ □
□ □ □ □ □ □ □ □ ■ □ □
□ □ □ □ □ □ □ □ □ ■ □
□ □ □ □ □ □ □ □ □ □ ■
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:26:06+00:00Added an answer on June 18, 2026 at 12:26 am

    Okay, so the Bresenham’s algorithm is attractive because it uses integer math (it makes the simplifying assumption that pixels are located at integer x,y coordinates).

    An algorithm to solve the number of pixels for some row at an integer y would do something like this:

    count = 1
    y_query = your query row
    x_intercept = intercept of your line at y_query.
    round x_intercept to the nearest integer. 
    (x_intercept, y_query) now define a pixel in the row
    

    The idea is to go left and right from this coordinate and see if you are still in the y_query row:

    //going left
    x_new = x_intercept - 1
    y_new = the y intercept for the line given x_new
    round y_new to the nearest integer
    if (y_new == y_query), add 1 to our count of pixels in this row, else break;
    

    Do the same for x_new = x_intercept + 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm . I need it to
There was this problem that has been asked about implementing a load byte into
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
There is this way, of course: OuterClass.this . But that's very clumsy. Ideally, there'd
there's this interesting problem i can not solve myself. I will be very glad,
There's this very simple bit a code <asp:TextBox ID=txbVipNumber runat=server /> <asp:TextBoxWatermarkExtender ID=tbweVipNumber runat=server
Are there any well known algorithms for figuring out the Recommended Items that websites
I implemented a parallel merge sort algorithm from Cormen's well-known text. I wrote it
Is there a known, efficient algorithm for finding the closest group of three points
This seems like it should be a well known problem, but I haven't been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.