开发者

How does computer draw a line??

Windows GDI has these functions:

MoveTo();

LineTo();

They accept coordinates where to start d开发者_如何学Pythonrawing and where to stop drawing.

But how are these functions implemented?? (especially LineTo)

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

How is this line drawn exactly??


Yes, they calculate each individual point between A and B.

The most common way to do this efficiently is known as Bresenham's Line Algorithm.

Note that Windows LineTo does not draw the last point. When line segments are drawn one after another, this prevents the endpoints from being double drawn.


nobody who never saw the Windows source code can answer this in-depth... BUT Windows is just as any other software: it needs some algorithm to draw a line... one such algorithm you can see here http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

The Moveto is "easier" in that it just updates the current coordinates the system know of...


It doesn't need to calculate all points between A and B (which are infinite) but only the discrete pixels between A and B. That's usually a standard line rasterization algorithm. See Wikipedia for Bresenham's line rasterization algorithm, which is the standard school book example and usually the base for more flexible rasterization algorithms.


I suspect there is more going on that just (a form of) Bresenham as there is also (optional) anti-aliasing. see this article for what might be the implemented algoritm (Xiaolin Wu's line algorithm)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜