电脑怎么画线?

发布于 2024-11-27 07:07:34 字数 168 浏览 0 评论 0原文

Windows GDI 具有以下函数:

MoveTo();

线到();

它们接受开始绘图和停止绘图的坐标。

但这些功能是如何实现的呢? (尤其是LineTo)

他们需要计算A点和B点之间的所有点吗?

这条线具体是怎么画的??

Windows GDI has these functions:

MoveTo();

LineTo();

They accept coordinates where to start drawing 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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

土豪我们做朋友吧 2024-12-04 07:07:34

是的,他们计算 A 和 B 之间的每个单独的点。

有效地执行此操作的最常见方法称为 布雷森纳姆直线算法

请注意,Windows LineTo 不会绘制最后一个点。当一条一条地绘制线段时,这可以防止端点被重复绘制。

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.

夏雨凉 2024-12-04 07:07:34

没有看过 Windows 源代码的人可以深入回答这个问题......
但是 Windows 与任何其他软件一样:它需要某种算法来画一条线...您可以在此处看到一种这样的算法 http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

Moveto 更“简单”,因为它只更新系统知道的当前坐标 的...

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...

油饼 2024-12-04 07:07:34

它不需要计算 A 和 B 之间的所有点(无限),而只需要计算 A 和 B 之间的离散像素。这通常是标准线光栅化算法。请参阅 Wikipedia 了解 Bresenham 的线光栅化算法,这是标准的教科书示例,通常是基础用于更灵活的光栅化算法。

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.

中性美 2024-12-04 07:07:34

我怀疑除了布雷森汉姆(Bresenham)之外还有更多的事情发生,因为还有(可选)抗锯齿功能。请参阅本文了解可能实现的算法(Xiaolin Wu 的直线算法)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文