Answer the question
In order to leave comments, you need to log in
What is the problem with using Bresenham's algorithm?
Hello!
There is a task: pixel by pixel to connect the points given by coordinates.
To solve this, I use the above algorithm like this:
def print_bres(a, b):
x1, x2, y1, y2 = a[0], b[0], a[1], b[1]
delta_x = abs(x2 - x1)
delta_y = abs(y2 - y1)
sign_x = 1 if x1 < x2 else -1
sign_y = 1 if y1 < y2 else -1
error = delta_x - delta_y
print ("%d %d" %(x2, y2))
while (x1 != x2) or (y1 != y2):
print ("%d %d" %(x1, y1))
error2 = error*2
if error2 > -delta_y:
error -= delta_y
x1 += sign_x
if error2 < delta_x:
error += delta_x
y1 += sign_y
counter = 0
while counter != len(v) - 1:
for i in range(counter, len(v)-1):
print_bres(v[counter], v[i])
counter += 1
Answer the question
In order to leave comments, you need to log in
And in Octave separate points or lines between points are drawn? Your implementation of the algorithm, for the segment (0, 0) - (2,3) outputs:
2 3
0 0
1 1
1 2
print ("%d %d" %(x2, y2))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question