How does a computer draw a line?

Windows GDI performs the following functions:

MoveTo ();

LineTo ();

They take the coordinates where to start drawing and stop drawing.

But how are these features implemented? (especially LineTo)

Do they need to calculate all the points between point A and point B?

How is this line drawn exactly?

+6
source share
4 answers

Yes, they calculate every single point between A and B.

The most common way to do this is effectively known as the Bresenham line algorithm .

Please note that Windows LineTo does not display the last dot. When line segments are drawn one after another, this prevents the double drawing of end points.

+7
source

no one who has ever seen the source code of Windows can answer this in detail ... BUT Windows is just like any other software: it needs some kind of algorithm to draw a line ... one such algorithm you can see here http : //en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

Moveto is โ€œsimplerโ€ in that it simply updates the current coordinates that the system knows about ...

+2
source

It is not necessary to calculate all the points between A and B (which are infinite), but only the discrete pixels between A and B. This is usually the standard screen rasterization algorithm. See Wikipedia for the Bresenham line rasterization algorithm, which is a standard example of a school book and is usually the basis for more flexible rasterization algorithms.

+1
source

I suspect that this happens simply (form) Breshenem, because there is also (optional) anti-aliasing. see this article for what might be an implemented algorithm (Xiaolin Wu line algorithm)

0
source

Source: https://habr.com/ru/post/893890/


All Articles