Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for drawing lines on the plane

What is the algorithm for drawing line on the plane (pointwise), if it is not horizontal or vertical?

like image 894
Peter17 Avatar asked May 14 '11 09:05

Peter17


People also ask

Which algorithm is used for line drawing?

Bresenham's line algorithm is a line drawing algorithm that determines the points of an n-dimensional raster that should be selected in order to form a close approximation to a straight line between two points.

What is DDA line drawing algorithm?

The Digital Difference Analyzer (DDA) algorithm is used to draw lines on a screen in an incrementally. The algorithm is called the Digital Difference Analyzer because it interpolates points based on the difference between the start and end points. The algorithm itself is very easy to understand and implement.

Why we use Bresenham's algorithm?

Advantages of Bresenham Line Drawing Algorithm- It is easy to implement. It is fast and incremental. It executes fast but less faster than DDA Algorithm. The points generated by this algorithm are more accurate than DDA Algorithm.


2 Answers

See Bresenham's algorithm.

like image 198
Yakov Galka Avatar answered Sep 26 '22 02:09

Yakov Galka


There is no 'pointwise' algorithm - points are infinitesimally small, so any algorithm based on points would take an infinite time to complete.

Instead, lines are drawn based on a notional pen width and calculating how many and what intensity of pixels that stroking the line with a pen would cover.

If you merely want to turn pixels on and off like it's the 1970s, then use one of the Brensenham's algorithm family.

Most modern computer graphics use anti-aliasing algorithms - either stroking, sub-sampling or exact pixel coverage - and sometimes parallel algorithms in the GPU ( for example drawing a line by projecting a thin rectangle onto the plane, or performing coverage calculations per pixel in parallel ).

Many graphics algorithms are based on Bezier curves; straight lines are just curves where the control points are in a line, so the algorithms for drawing them are the same, though may make a few optimisations.

like image 20
Pete Kirkham Avatar answered Sep 26 '22 02:09

Pete Kirkham