Locating Pixels with Bresenham's line algorithm

In summary, The person is looking for help locating the pixels of a line drawn from (0,0) to (-4,-8) using Bresenham's algorithm without using a computer. They have tried various algorithms and are asking for help, but are told to use a Google search for "wiki bresenham's algorithm." The person is also asked if they are unable to turn the pseudocode from the wiki into working code.
  • #1
armin11
66
0
hi,I wanted to locate the pixels of a line drawn from (0,0) to (-4,-8) with bresenham's algorithm.I couldn't find a suitable algorithm for finding these pixel locations.Can anyone help me please?(the algorithm can be without computer and work by hand)
 
Technology news on Phys.org
  • #3
I've searched so much and tried every algorithm they have written ,but they don't work.can anybody help please?
 
  • #4
This smells like a homework question... In which case you're in the wrong forum.

Also not a hard one. The wiki has full (and rather simple) pseudocode for Bresenham's. Can you really not turn that into working code? That's all you need to do.
 
  • #5


Bresenham's line algorithm is a commonly used method for drawing lines on a computer screen. It works by calculating the coordinates of pixels that lie on the line between two specified points. While this algorithm is typically used in computer graphics, it can also be applied by hand.

To locate the pixels of a line drawn from (0,0) to (-4,-8), we can follow these steps:

1. Calculate the slope of the line using the formula: m = (y2-y1)/(x2-x1). In this case, m = (-8-0)/(-4-0) = 2.

2. Determine the major axis of the line. This is the axis with the larger absolute change in coordinates. In this case, the major axis is the y-axis.

3. Starting from the first point (0,0), we can plot the first pixel on the y-axis (since it is the major axis) and mark it as (0,0).

4. Next, we can use the slope to determine the next pixel on the line. In this case, for every change of 1 unit on the major axis (y-axis), the minor axis (x-axis) changes by 1/2 unit (since m=2). Therefore, we can plot the next pixel at (0,1).

5. We repeat this process, moving 1 unit on the major axis and 1/2 unit on the minor axis, until we reach the end point (-4,-8).

6. The pixels that lie on the line between (0,0) and (-4,-8) are: (0,0), (0,1), (-1,2), (-1,3), (-2,4), (-2,5), (-3,6), (-3,7), and (-4,8).

I hope this helps you locate the pixels using Bresenham's algorithm without a computer. Please let me know if you have any further questions.
 

FAQ: Locating Pixels with Bresenham's line algorithm

1. What is Bresenham's line algorithm?

Bresenham's line algorithm is a method for determining which pixels to plot in order to form a straight line between two given points. It is commonly used in computer graphics and image processing.

2. How does Bresenham's line algorithm work?

The algorithm uses a series of calculations to determine the most efficient way to plot pixels along a line. It takes into account the slope of the line and the distance between the starting and ending points to determine the best sequence of pixels to plot.

3. What are the advantages of using Bresenham's line algorithm?

Bresenham's line algorithm is an efficient and fast method for drawing straight lines. It uses only integer arithmetic, making it suitable for implementation in hardware or low-level programming languages. It also produces very accurate results compared to other methods.

4. What are the limitations of Bresenham's line algorithm?

One limitation of Bresenham's line algorithm is that it can only draw straight lines between two given points. It cannot be used to draw curves or other complex shapes. Additionally, the algorithm may produce inaccurate results if the slope of the line is very steep or close to horizontal.

5. How is Bresenham's line algorithm used in scientific research?

Bresenham's line algorithm is commonly used in scientific research for image processing and computer graphics applications. It can be used to accurately draw and analyze data visualizations, such as graphs and charts, and to enhance and manipulate images for analysis.

Similar threads

Back
Top