bresenham

Drawing a line using individual pixels in OpenGl core

你。 提交于 2019-12-12 03:55:11
问题 I am trying to implement a line drawing algorithm in OpenGl. I have learnt the basics of using OpenGl from learnopengl. In the line drawing algorithm I need to set the individual pixel itself. I don't understand how to use the OpenGl at pixel level. I tried searching for the implementation bresenham's line algorithm in opengl, everywhere the implementation uses the function glDrawPixels which is not supported in OpenGl3.3. Is there anything that I'm missing in OpenGl3.3? 回答1: The point of

Bresenham line doesn't terminate

半世苍凉 提交于 2019-12-08 03:20:33
问题 I've implemented the Bresenham algorithm from Wikipedia in python but for some lines it doesn't work, like from 1,0 to 0,1 it doesn't stop and keeps going on to make a super long line def line(x0, y0, x1, y1): dx = x1 - x0 dy = y1 - y0 sx = x0 < x1 and 1 or -1 sy = y0 < y1 and 1 or -1 err = dx - dy points = [] x, y = x0, y0 while True: points += [(x, y)] if x == x1 and y == y1: break e2 = err * 2 if e2 > -dy: err -= dy x += sx if e2 < dx: err += dx y += sy return points 回答1: You are missing

please explain this Bresenham Line drawing code for me

ぃ、小莉子 提交于 2019-12-06 02:02:42
I have searched throughout the Internet and found hundreds of implementation of Bresenham's line drawing algorithm. But, one thing I found strange is, only two or three of them can cover all of the eight octets. still, they are being used in many applications. For example, this lady implemented this version (line 415) of Bresenham's algorithm. But, it doesn't cover the whole 360 degrees. This guy here seems to be developing a library. But still it doesn't work properly. Can you tell me why? This guy's implementation works fine. But, I suppose it is not Bresenham's Algorithm. It has a very few

Bresenham concentric circles leaving empty pixels

故事扮演 提交于 2019-12-05 17:06:55
I am using the midpoint circle algorithm, also known as Bresenham's, to draw concentric circles. The difference between each circle's radius and that of the next is always 1, so the final result should be a full circular area. However, some pixels are left empty, as shown in the attached image. I'm using Javascript to paint on an HTML5 canvas, manipulating the canvas.getContext("2d").getImageData(...).data array. The circles are alternatively white and red, and the empty pixels are black. You might have to zoom in in order to see what I mean properly. I'm trying to add some code to the

efficient algorithm for drawing circle arcs?

本秂侑毒 提交于 2019-12-04 10:37:56
I am using the mid-point circle algorithm (bresenham circle) to efficiently draw whole circles. Is there something similar to draw circle arcs? I would like to specify a start angle and end angle and have only that portion of the circle drawn. Thanks in advance! EDIT: I would like to draw filled circle arcs too, i.e pie-slices. :) Doesn't your platform already have some library that handles drawing these kinds of shapes? Drawing a filled pie-slice: First, cut the pie vertically and horizontally, into quarters. If your pie slice is exactly one of those quarters, or fits entirely inside one of

Drawing lines with Bresenham's Line Algorithm

不羁岁月 提交于 2019-12-04 03:43:07
My computer graphics homework is to implement OpenGL algorithms using only the ability to draw points. So obviously I need to get drawLine() to work before I can draw anything else. drawLine() has to be done using integers only. No floating point. This is what I was taught. Basically, lines can be broken up into 4 different categories, positive steep, positive shallow, negative steep and negative shallow. This is the picture I am supposed to draw: and this is the picture my program is drawing: The colors are done for us. We are given vertices and we need to use Bresenham's Line algorithm to

Circle with thickness drawing algorithm

蹲街弑〆低调 提交于 2019-12-01 19:33:23
问题 Currently I am using Bresenham's circle drawing algorithm, which draws circles fine, however I would like a relatively fast and efficient way to draw a circle with a specified thickness (since Bresenham's method only draws a single pixel thickness). I realise that I could simply draw multiple circles with different radii, but I believe this would be very inefficient (and efficiency is important because this will be running on an Arduino where every microsecond is precious). I am currently

Simplified Bresenham's line algorithm: What does it *exactly* do?

喜欢而已 提交于 2019-11-28 21:31:33
Based on Wikipedia's article on Bresenham's line algorithm I've implemented the simplified version described there, my Java implementation looks like this: int dx = Math.abs(x2 - x1); int dy = Math.abs(y2 - y1); int sx = (x1 < x2) ? 1 : -1; int sy = (y1 < y2) ? 1 : -1; int err = dx - dy; while (true) { framebuffer.setPixel(x1, y1, Vec3.one); if (x1 == x2 && y1 == y2) { break; } int e2 = 2 * err; if (e2 > -dy) { err = err - dy; x1 = x1 + sx; } if (e2 < dx) { err = err + dx; y1 = y1 + sy; } } Now I do understand that err controls the ratio between steps on the x-axis compared to steps on the y

Walk a line between two points in a 3D voxel space visiting all cells

♀尐吖头ヾ 提交于 2019-11-28 09:26:11
I have a line-of-sight problem I need to solve by visiting all possible cells in a 3D voxel space between two (non-grid-aligned) points. I have considered using a 3D Bresenham algorithm, but it will skip out some cells. A naive implementation might be to just check points along the line at a higher resolution than the voxel grid, but I was hoping for a more intelligent solution. Anyone got any leads? Came up with this, or see: http://jsfiddle.net/wivlaro/mkaWf/6/ function visitAll(gx0, gy0, gz0, gx1, gy1, gz1, visitor) { var gx0idx = Math.floor(gx0); var gy0idx = Math.floor(gy0); var gz0idx =

algorithm to rasterize and fill a hypersphere?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 16:17:34
I'm trying to rasterize and fill a hypersphere. In essence, I have a d-dimensional grid of fixed size and a sphere (center, radius) and want to find out which cells of the grid overlap with the sphere and store their coordinates. I am aware of the Midpoint circle algorithm which takes advantage of 8-way mirroring and produces the outer cells (border) of a circle. I have also altered the linked wikipedia code so as to fill the circle (that is, to produce the coordinates of all cells inside the border). However I am unaware of any algorithms for higher dimension. For example in 4d, I've been