如何使用 Bresenham 创建任意粗细的线? [英] how do I create a line of arbitrary thickness using Bresenham?

查看:28
本文介绍了如何使用 Bresenham 创建任意粗细的线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Bresenham 的算法来绘制线条,但它们(当然)的厚度是一个像素.我的问题是绘制任意粗细线的最有效方法是什么?

I am currently using Bresenham's algorithm to draw lines but they are (of course) one pixel in thickness. My question is what is the most efficient way to draw lines of arbitrary thickness?

我使用的语言是 C.

推荐答案

我认为最好的方法是画一个矩形而不是一条线,因为具有宽度的线是一个二维对象.尝试绘制一组平行线以避免过度绘制(以减少写入带宽)和绘制不足(丢失像素)将非常复杂.从起点和终点和宽度计算矩形的角点并不太难.

I think the best way is to draw a rectangle rather than a line since a line with width is a two dimensional object. Tring to draw a set of parallel lines to avoid overdraw (to reduce write bandwidth) and underdraw (missing pixels) would be quite complex. It's not too hard to calculate the corner points of the rectangle from the start and end point and the width.

因此,按照下面的评论,执行此操作的过程将是:-

So, following a comment below, the process to do this would be:-

  1. 创建一个与所需线条长度相同、宽度与所需宽度相同的矩形,因此 (0,0) 到 (width,length)
  2. 使用 2D 变换将矩形角坐标旋转并平移到所需位置
  3. 使用硬件加速渲染器(例如 OpenGL 四边形*)或使用软件光栅化器对旋转的矩形进行光栅化.它可以使用四边形光栅化器或一对三角形(例如左上角和右下角)进行渲染.

注意 *:如果您使用 OpenGL,您也可以同时执行第 2 步.当然,使用 OpenGL 确实意味着了解 OpenGL(大而复杂),而这个应用程序可能会使在开发的后期阶段实现这一点变得棘手.

Note *: If you're using OpenGL you can also do Step 2 at the same time. Of course, using OpenGL does mean understanding OpenGL (big and complex) and this application may make that a tricky thing to implement at such a late stage in development.

这篇关于如何使用 Bresenham 创建任意粗细的线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆